InterviewSolution
Saved Bookmarks
| 1. |
Write down the Syntax for all the loops in Shell Scripting. |
|
Answer» In shell scripting, you can USE three looping statements as given below:
Syntax is as follows:
Syntax: for VAR in word1 word2 ... wordN do Statement to be executed doneExample: for a in 1 2 3 4 5 6 7 8 9 10 do if [ $a == 3 ] then break fi echo "Iteration no $a" doneOutput” $bash -f main.sh Iteration no 1 Iteration no 2
Syntax: while command do Statement to be executed doneExample: a=0 while [ $a -lt 3 ] do echo $a a=`expr $a + 1` doneOutput: $bash -f main.sh 0 1 2 3
Syntax: until command do Statement to be executed until command is true doneExample: a=0 until [ $a -gt 3 ] do echo $a a=`expr $a + 1` doneOutput: $bash -f main.sh 0 1 2 3 |
|