Created
July 18, 2015 03:48
-
-
Save yangkun/65e6bb5db3a0293a3035 to your computer and use it in GitHub Desktop.
[bash] loop example
This file contains 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 | |
#Basic | |
for i in {1..5} | |
do | |
echo "$i" | |
done | |
#Basic and leading zero | |
for num in {1..5} | |
do | |
value=$(printf "%02d" $num) | |
echo $value | |
done | |
# Countdown - BOOM !! | |
START=1 | |
END=5 | |
echo "Countdown" | |
for (( c=$START; c<=$END; c++ )) | |
do | |
echo -n "$c " | |
sleep 1 | |
done | |
echo | |
echo "Boom!" | |
## save $START, just in case if we need it later ## | |
i=$START | |
while [[ $i -le $END ]] | |
do | |
echo "$i" | |
((i = i + 1)) | |
done | |
## define an array ## | |
arrayname=( Dell HP Oracle ) | |
## get item count using ${arrayname[@]} ## | |
for m in "${arrayname[@]}" | |
do | |
echo "${m}" | |
# do something on $m # | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment