Shell control flow commands

31 May 2007

You keep forgetting how to do control flow in shell scripts.

#!/bin/bash

for VAR in ITEMA ITEMB ITEMC ITEMD; do
  # do something with $VAR
done

for VAR in {1..5}; do
  # do something with $VAR
done

while [ condition ]; do
  # do something
done

if [ "$str1" == "$str2" ]; then
  # do something
elif [ other_condition ]; then
  # do another thing
else
  # do something else
fi