Unix 25
Unix 25
which causes hangup, interrupt, quit and kill to be ignored both by the procedure and by invoked commands.
which resets the traps for signals 2 and 3 to their default values. A list of the current values of traps may be obtained by writing
trap
The procedure scan (Figure 5) is an example of the use of trap where there is no exit in the trap command. scan takes each directory in the current directory, prompts with its name, and then executes commands typed at the terminal until an end of file or an interrupt is received. Interrupts are ignored while executing the requested commands but cause termination when scan is waiting for input.
d=`pwd` for i in * do if test -d $d/$i then cd $d/$i while echo "$i:" trap exit 2 read x do trap : 2; eval $x; done fi done
Figure 5. The scan command read x is a built-in command that reads one line from the standard input and places the result in the variable x. It returns a non-zero exit status if either an end-of-file is read or an interrupt is received.
The trap turns off the signals specified so that they are ignored by subsequently created commands and exec replaces the shell by the command specified.
Most forms of input output redirection have already been described. In the following word is only subject to parameter and command substitution. No file name generation or blank interpretation takes place so that, for example,
echo ... >*.c
will write its output into a file whose name is *.c. Input output specifications are evaluated left to right as they appear in the command. > word The standard output (file descriptor 1) is sent to the file word which is created if it does not already exist. >> word