July 2017
Beginner
208 pages
3h 7m
English
Sometimes when you are coding a script, you encounter a situation where you would like to exit the loop early, before the ending condition is met. This can be accomplished using the break and continue commands.
Here is a script that shows these commands. I am also introducing the sleep command which will be talked about in detail in the next script.
#!/bin/sh # # 5/3/2017 # echo "script9 - Linux Scripting Book" FN1=/tmp/break.txt FN2=/tmp/continue.txt x=1 while [ $x -le 1000000 ] do echo "x:$x" if [ -f $FN1 ] ; then echo "Running the break command" rm -f $FN1 break fi if [ -f $FN2 ] ; then echo "Running the continue command" rm -f $FN2 continue fi let x++ sleep 1 done echo "x:$x" echo "End of script9" exit ...
Read now
Unlock full access