流程控制

if else

if [ expression ]; then
  statement
else
  statement
fi


if [ expression ]; then
  statement
elif [ expression ]; then
  statement
else
  statement
fi

循环

for

for i in item1 item2 ... itemN
do
    statement
    ...
    statement
done

arr=(1 2 3)
for i in ${arr[@]}
do
    statement
    ...
    statement
done

while

while condition
do
    command
done

无限循环

while :
do
  # command
done

while true do command done

for (( ; ; )) do command done

until

until condition
do
    command
done

跳出循环

break

continue

case

case $var in
  pattern)
    statement
    ;;
  *)
    statement
    ;;
esac

Last updated