2.1 Control Flow - For: Who - Grep $1
2.1 Control Flow - For: Who - Grep $1
then
sh wg fred
is equivalent to
who | grep fred
UNIX files have three independent attributes, read, write and execute. The UNIX command chmod (1) may be used to make a file executable. For example,
chmod +x wg
will ensure that the file wg has execute status. Following this, the command
wg fred
is equivalent to
sh wg fred
This allows shell procedures and programs to be used interchangeably. In either case a new process is created to run the command.
As well as providing names for the positional parameters, the number of positional parameters in the call is available as $#. The name of the file being executed is available as $0. A special shell parameter $* is used to substitute for all positional parameters except $0. A typical use of this is to provide some default arguments, as in,
nroff -T450 -ms $*
The command
tel fred
The for loop notation is recognized by the shell and has the general form
for name in w1 w2 ... do command-list done
A command-list is a sequence of one or more simple commands separated or terminated by a newline or semicolon. Furthermore, reserved words like do and done are only recognized following a newline or semicolon. name is a shell variable that is set to the words w1 w2 ... in turn each time the command-list following do is executed. If in w1 w2 ... is omitted then the loop is executed once for each positional parameter; that is, in $* is assumed.
Another example of the use of the for loop is the create command whose text is