Bash: foreach loop over piped lines
Another quick bash example where the ratio of time-spent-searching to ease-of-code was pretty bad...
You have a command (in this case ls -1) you want to iterate over each line from the command to test for something. Do as follows:
ls -1 /usr/java | while read line; do if [ "${line}" = "jdk1.5" ] then echo "Time to upgrade" fi done
The contents of the if statement are unimportant. We pipe the multiple lines from ls in to a while loop (using the vertical bar on line 2). The while lets us declare a variable "line" for each row from ls. "line" can then be tested / manipulated as you like.