Created
October 16, 2013 11:43
-
-
Save newtonsbm/7006443 to your computer and use it in GitHub Desktop.
how to do loop in bash scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# nested-loop.sh: Nested "for" loops. | |
outer=1 # Set outer loop counter. | |
# Beginning of outer loop. | |
for a in 1 2 3 4 5 | |
do | |
echo "Pass $outer in outer loop." | |
echo "---------------------" | |
inner=1 # Reset inner loop counter. | |
# =============================================== | |
# Beginning of inner loop. | |
for b in 1 2 3 4 5 | |
do | |
echo "Pass $inner in inner loop." | |
let "inner+=1" # Increment inner loop counter. | |
done | |
# End of inner loop. | |
# =============================================== | |
let "outer+=1" # Increment outer loop counter. | |
echo # Space between output blocks in pass of outer loop. | |
done | |
# End of outer loop. | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment