O.1. Analyzing Scripts
Examine the following script. Run it, then explain what it does. Annotate the script and rewrite it in a more compact and elegant manner.
#!/bin/bashMAX=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 happens when you comment out this line? Why? done echo "Number = $nr" exit 0 |
---
Explain what the following script does. It is really just a parameterized command-line pipe.
#!/bin/bashDIRNAME=/usr/binFILETYPE="shell script" LOGFILE=logfilefile "$DIRNAME"/* | fgrep "$FILETYPE" | tee $LOGFILE | wc -lexit 0 |
---
Examine and explain the following script. For hints, you might refer to the listings for find and stat.
#!/bin/bash# Author: Nathan Coulter# This code is released to the public domain.# The author gave permission to use this code snippet in the ABS Guide.find -maxdepth 1 -type f -printf '%f 00' | { while read -d $' |