June 2006
Intermediate to advanced
64 pages
2h 42m
English
if
ifcondition1thencommands1[ elifcondition2thencommands2] . . . [ elsecommands3] fi
If condition1 is met, do
commands1; otherwise, if
condition2 is met, do
commands2; if neither is met, do
commands3. Conditions are often specified with
the test and [[ ]] commands. See test and
[[ ]] for a full list of
conditions, and see additional Examples under : and
exit.
Insert a 0 before numbers less than 10:
if [ $counter -lt 10 ] then number=0$counter else number=$counter fi
Make a directory if it doesn't exist:
if [ ! -d $dir ]; then
mkdir -m 775 $dir
fiRead now
Unlock full access