System information
An Introduction to Shells in General
Axis Communications AB provides NO support for application development of any kind. The information
here is provided "as is", and there is no guarantee that any of the examples shown will work in your
particular application.
Revision 1.02 October 2002 68
The case statement
The case statement enables you to compare a pattern with several other patterns and execute a
block of code if a match is found. The syntax of the case statement is:
case string in
str1)
commands;;
str2)
commands;;
*)
commands;;
esac
string
is compared to str1 and str2. If one of these strings matches string1, the
commands up until the double semicolon (;;) are executed. If neither str1 nor str2 matches
string, the commands associated with the asterisk are executed. This is the default case
condition because the asterisk matches all strings.
The for statement
The for statement executes the commands that are contained within it a specified number of
times. The syntax of the for statement is:
for var1 in list
do
commands
done
In this form, the for statement executes once for each item in the list. This list can be a variable
that contains several words separated by spaces, or it can be a list of values that is typed directly
into the statement. Each time through the loop, the variable var1 is assigned the current item in
the list, until the last one is reached.
The second form of for statement has the following syntax:
for var1
do
statements
done
In this form, the for statement executes once for each item in the variable var1. When this
syntax of the for statement is used, the shell program assumes that the var1 variable contains
all the positional parameters that were passed in to the shell program on the command line.
The
while statement
Another iteration statement offered by the shell programming language is the
while statement.
This statement causes a block of code to be executed while a provided conditional expression is
true. The syntax for the while statement is the following: