Skip to content

Instantly share code, notes, and snippets.

@yangkun
Created July 18, 2015 03:48
Show Gist options
  • Save yangkun/65e6bb5db3a0293a3035 to your computer and use it in GitHub Desktop.
Save yangkun/65e6bb5db3a0293a3035 to your computer and use it in GitHub Desktop.
[bash] loop example
#!/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