16 Break and Continue - kumar159man/MyShellLearning GitHub Wiki
Demonstration of break in shell script
#!/usr/bin/bash
for((;;))
do
read -p "Enter a number" num
if [[ $num -eq 5 ]]
then
echo "As 5 is entered script will be stopped"
break
fi
done
myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ ./break.sh Enter a number12 Enter a number13 Enter a number14 Enter a number15 Enter a number17 Enter a number5 As 5 is entered script will be stopped
Print 1 to 10 except 5
#!/usr/bin/bash
for i in $(seq 1 10)
do
if [[ $i -eq 5 ]]
then
continue
fi
echo $i
done
myubuntu@myubuntu-VirtualBox:~/Desktop/shellScripts$ ./continue.sh 1 2 3 4 6 7 8 9 10