Shell Scripting Important Syntax for loop Switch Case

Important  If Condition, For Loop While Loop
if Condition : Syntax
If [ condition ] ; then
  {statement}
elif [condition] ; then
{statement }
fi
Note : Semicolon and then is important.




For Loop- Method -1
For ( ( c=1;c<=5;c++))
do
echo “ Welcome $c times “
done

Method 2
for c in 1 2 3 4 5
do
echo "welcome $c Times"
done
Method 3
for c in {1..5}
do
echo "welcome $c Times"
done


Read variable in shell script
read { variable name }

While Loop Statement
c=3;
while [ $c -le 15 ]
do
echo "Welcome $c times"
((c++))
done

Switch case Example
Check=1
Case $check in
1) echo “redhat;;
2) echo “ubunut” ;;
*) echo “none”
esac
Trigger the Back Ground Process to foreground
Process Id Vary from 0 to 65535

Shell Script How To Do The Addition With Variable
S=$((10+$i)) just like for loop for ((;;))

Related post