# declare a variable
name="Saplyn"
# access the variable
echo "I'm $name!"
$? # exit status of the last command
$$ # process ID of the current script
$! # process ID of the last background command
$0 # name of the script
$1 ... $9 # arguments passed to the script
$# # number of arguments passed to the script
$* # all arguments passed to the script
${#name} # length of the variable
${#1} # length of the first argument
# for-in
for i in 1 2 3; do
echo $i
done
for i in {1..3}; do
echo $i
done
# c-style for
for ((i=0; i<3; i++)); do
echo $i
done
# while
i=0
while [ $i -le 5 ]; do
echo "Executing \`while\` loop: $i"
i=$((i + 1))
done
# until
i=0
until [ $i -ge 5 ]; do
echo "Executing \`until\` loop: $i"
i=$((i + 1))
done
# break
for i in {1..10}; do
if [ "$i" -eq 5 ]; then
break
fi
echo "Loop: $i"
done
# break multiple loops
for i in {1..10}; do
for j in {1..2}; do
if [ "$i" -eq 5 ]; then
break 2
fi
echo "($i, $j)"
done
done
# continue
for i in {1..10}; do
if [ "$i" -eq 5 ]; then
continue
fi
echo "Loop: $i"
done
# continue multiple loops
for i in {1..5}; do
for j in {1..2}; do
if [ "$i" -eq 3 ]; then
continue 2
fi
echo -n "($i, $j) "
done
echo "($i)"
done