Previous Table of Contents Next


CONTROL COMMANDS

case value in
     pattern1 )     commands1 ;;
     pattern2 )     commands2 ;;
     . . .
     patternn )     commandsn ;;
esac

Execute commands associated with the pattern that matches value.

for variable in word1 word2 . . . wordn
do
     commands
done

Execute commands once for each word, setting variable to successive words each time.

for variable
do
     commands
done

Execute commands once for each positional parameter, setting variable to successive positional parameters each time.

if command1
then
     commands
fi

Execute commands if command1 returns a zero exit status.

if command1
then
     commands2
else
     commands3
fi

Execute commands2 if commands1 returns a zero exit status, otherwise execute commands3.

if command1
then
     commands
elif command2
then
     commands
. . .
elif commandn
then
     commands
else
     commands
fi

If command1 returns a zero exit status, or command2 returns a zero exit status, or commandn returns a zero exit status, then execute the commands corresponding to the if/elif that returned a zero exit status. Otherwise, if all the if/elif commands return a non-zero exit status, execute the commands between else and fi.

select variable in word1 word2 . . . wordn
do
     commands
done

Display a menu of numbered choices word1 through wordn followed by a prompt (#? or $PS3). Execute commands for each menu selection, setting variable to each selection and REPLY to the response until a break, exit, or EOF is encountered.

select variable
do
     commands
done

Display a menu of numbered choices for each positional parameter followed by a prompt (#? or $PS3). Execute commands for each menu selection, setting variable to each selection and REPLY to the response until a break, exit, or EOF is encountered.

until command1
do
     commands
done

Execute commands until command1 returns a zero exit status

while command1
do
     commands
done

Execute commands while command1 returns a zero exit status.


Previous Table of Contents Next
1