The meta-character '<' must be followed by a token that
represents a file name. It indicates that the command before
this meta-character reads its input from this file (instead of
stdin of the shell). Thus, the meta-character '<' must follow
the name of a command. Note that there can be spaces between the
command name and '<', and between '<' and the file
name. However, this does not have to be the case. That is,
both cat < file
and cat<file
are valid
and have the same effect.
The meta-character '>' must be followed by a token that
represents a file name. It indicates that the command before
this meta-character writes its output to this file (instead of
stdout of the shell). Thus, the meta-character '>' must follow
the name of a command. Again, there can be spaces between the
command name and '>', and between '>' and the file
name. However, this does not have to be the case. That is,
both ls > file
and ls>file
are valid
and have the same effect.
The meta-character '|' (i.e., pipe sign) allows multiple
commands to be connected. When the shell encounters the '|'
character, the output of the command before the pipe sign must
be connected to the input of the command after the pipe
sign. This requires that there is a valid command before and
after the pipe. Also, note that there can be multiple pipe signs
on the command line. For example, your shell has to be able to
process an input such as cat f | sort | wc
. With this
command, the output of the cat
command is redirected to
the input of sort
, which in turn sends its output to
the input of the wc
program. With regard to white
spaces separating the meta-character from the commands, the same
rules as above apply.
The code should also support a signal handling procedure: when the user hits Ctrl-Z, it asks the user to repeat Ctrl-Z one more time. Only after two Ctrl-Z signals, this shell will quit. Note that Ctrl-Z sends a SIGTSTP signal.