Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting | ||
---|---|---|
Prev | Appendix I. Exercises | Next |
Examine the following script. Run it, then explain what it does. Annotate the script, then rewrite it in a more compact and elegant manner.
#!/bin/bash MAX=10000 for((nr=1; nr<$MAX; nr++)) do let "t1 = nr % 5" if [ "$t1" -ne 3 ] then continue fi let "t2 = nr % 7" if [ "$t2" -ne 4 ] then continue fi let "t3 = nr % 9" if [ "$t3" -ne 5 ] then continue fi break # What heppens when you comment out this line? Why? done echo "Number = $nr" exit 0 |
---
A reader sent in the following code snippet.
while read LINE do echo $LINE done < `tail -f /var/log/messages` |
---
Analyze Example A-8, and reorganize it in a simplified and more logical style. See how many of its variables can be eliminated and try to optimize the script to speed up its execution time.
Alter the script so that it accepts any ordinary ASCII text file as input for its initial "generation". The script will read the first $ROW*$COL characters, and set the occurrences of vowels as "living" cells. Hint: be sure to translate the spaces in the input file to underscore characters.