shift done
is equivalent to
for i do ... done
shift is a shell command that renames the positional parameters $2, $3, ... as $1, $2, ... and loses $1.
Another kind of use for the while/until loop is to wait until some external event occurs and then run some commands. In an until loop the termination condition is reversed. For example,
until test -f file do sleep 300; done commands
will loop until file exists. Each time round the loop it waits for 5 minutes before trying again. (Presumably another process will eventually create the file.)
2.7 Control flow - if
Also available is a general conditional branch of the form,
if command-list then command-list else command-list fi
that tests the value returned by the last simple command following if.
The if command may be used in conjunction with the test command to test for the existence of a file as in
if test -f file then process file else do something else fi
An example of the use of if, case and for constructions is given in section 2.10.
A multiple test if command of the form
if ... then else ... if ... then ... else if ... ... fi fi
fi
may be written using an extension of the if notation as,
if ...
then elif then elif ... fi
... ... ... ...
The following example is the touch command which changes the `last modified' time for a list of files. The command may be used in conjunction with make (1) to force recompilation of a list of files.
flag= for i do case $i in -c) flag=N ;;