cd ~/it244/ex
mkdir ex24
cd ex24
for
Loopchmod 755 for_1.sh
./for_1.sh ~/*The ambiguous file reference ~/* is expanded into a list of all files in your home directory
for ... in ...
Loopchmod 755 for_2.sh
./for_2.shYou get the same results as with for_1.sh.
for
Loopchmod 755 for_3.sh
./for_3.shYou should see
0 1 2 3 4
while
Loopschmod 755 count_to_five.sh
./count_to_five.shYou should see
1 2 3 4 5
bash -x count_to_five.shNotice that each line of code is printed as it is executed, with the current value of the variable substituted for the variable name.
until
Loopwhile
loop script above.
chmod 755 count_until.sh
./count_until.sh 10You should see
1 2 3 4 5 6 7 8 9 10
continue
nano
, or your favorite editor,
create the script continue.shchmod 755 continue.sh
./continue.shYou should see
Adding 1 to 0 Adding 3 to 1 Adding 5 to 4 Adding 7 to 9 Adding 9 to 16 Adding 10 to 25 total: 35Notice that the echo command is not run for the values of 2, 4, 6 and 8.
break
nano
, or your favorite editor,
create the script break.sh
chmod 755 break.sh
touch 1 1.sh
chmod 755 1.sh
./break.shYou should see
First executable file: 1.sh