38
Case select
case string1 in
str1)
commands;;
str2)
commands;;
*)
commands;;
esac
string1 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 string1, the
commands associated with the asterisk are executed. This is the default case condition because
the asterisk matches all strings.
Iteration (Loops)
for var1 in list
do
commands
done
This executes once for each item in the list. This list can be a variable that contains several words
separated by spaces (such as output from ls or cat), 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.
while [ expression ]
do
commands
done
until [ expression ]
do
commands
done
Functions
Create a function:
fname(){
commands
}
Call it by using the following syntax: fname
Or, create a function that accepts arguments:
fname2 (arg1,arg2...argN){
commands
}
And call it with: fname2 arg1 arg2 ... argN
Commentaires sur ces manuels