Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (51 sloc) 1.1 KB

Loops

For

for i in `seq 1 10`; do
    echo $i
done
for i in $( ls ); do
    echo item: $i
done

Warning

IFS='\n'

Inline for

  • for a in *; do echo $a; done

While

COUNTER=0

while [  $COUNTER -lt 10 ]; do
    echo The counter is $COUNTER
    let COUNTER=COUNTER+1
done
while [ $# -gt 0 ]; do    # Until you run out of parameters . . .
  case "$1" in
    -d|--debug)
          # "-d" or "--debug" parameter?
          DEBUG=1
          ;;
    -c|--conf)
          CONFFILE="$2"
          shift
          if [ ! -f $CONFFILE ]; then
            echo "Error: Supplied file doesn't exist!"
            exit $E_CONFFILE     # File not found error.
          fi
          ;;
  esac
  shift   # Check next set of parameters.
done

Until

COUNTER=20

until [  $COUNTER -lt 10 ]; do
    echo COUNTER $COUNTER
    let COUNTER-=1
done