Im working in Bash, writing a fairly simple script (print the length of the longest filename in the working directory), but im having a bit of an issue with it. I can get the names of the files/dirs in the working directory by simply running ls -1, but i then nead to read in each line, compare it to the current working longest length, and replace it with the new length if longer. The web is startlingly devoid of basic help on how to read in lines with bash.
the lesson on bash scripts from school is no help either :/
How do i read in a line/arg in bash, and how do i know when there are no more args. Ive spent like 3 hours searching this shit on google to no avail.
Lazily, something like -
Code:for i in `ls *`; do wc -l $i; done 2> /dev/null | sort -nr | head -n 1
err... I misunderstood the requirements. The previous command will print the name of the largest file. the following will print the length of the longest filename.
Code:for i in `ls`; do echo $i | wc -c ; done 2> /dev/null | sort -nr | head -n 1