This project consists of creating a complete shell from scratch. A minimum set of features are required, from which you will build your own successful shell. This project allows us to see or review a very wide range of standard UNIX (and POSIX) features.
[x] <Word Uses the file specified by the Word parameter as standard input (file descriptor 0).
[x] >Word Uses the file specified by the Word parameter as standard output (file descriptor 1). If the file does not exist, the shell creates it. If the file exists and the noclobber option is on, an error results; otherwise, the file is truncated to zero length.
Note: When multiple shells have the noclobber option set and they redirect output to the same file, there could be a race condition, which might result in more than one of these shell processes writing to the file. The shell does not detect or prevent such race conditions.
[ ] >|Word Same as the >Word command, except that this redirection statement overrides the noclobber option.
Noclobber
When the shell encounters a command with output redirection, such as:
command > file
the first thing that happens is that the output stream is started by either creating file or, if file already exists, truncating it to zero length. This means that if command completely fails or doesn't even exist, file will end up with zero length. This can be a safety issue for new users who might overwrite (or truncate) a valuable file.
To avoid this, we can do one of two things. First we can use the ">>" operator instead of ">" so that output will be appended to the end of file rather than the beginning. Second, we can set the "noclobber" shell option which prevents redirection from overwriting an existing file. To activate this, we enter:
set -o noclobber
Once we set this option, attempts to overwrite an existing file will cause the following error:
bash: file: cannot overwrite existing file
The effect of the noclobber option can be overridden by using the >| redirection operator like so:
command >| file
To turn off the noclobber option we enter this command:
set +o noclobber
[x] >>Word Uses the file specified by the Word parameter as standard output. If the file currently exists, the shell appends the output to it (by first seeking the end-of-file character). If the file does not exist, the shell creates it.
[ ] ~<>Word Opens the file specified by the Word parameter for reading and writing as standard input.~
[ ] <<[-]Word Reads each line of shell input until it locates a line containing only the value of the Word parameter or an end-of-file character. The shell does not perform parameter substitution, command substitution, or file name substitution on the file specified. The resulting document, called a here document, becomes the standard input. If any character of the Word parameter is quoted, no interpretation is placed upon the characters of the document.
[x] <&Digit Duplicates standard input from the file descriptor specified by the Digit parameter
[x] >& Digit Duplicates standard output in the file descriptor specified by the Digit parameter
[x] <&- Closes standard input
[x] >&- Closes standard output
[ ] ~<&p Moves input from the co-process to standard input~
[ ] ~>&p Moves output to the co-process to standard output~
[x] [n]>>word where the optional n represents the file descriptor number. If the number is omitted, the redirection refers to standard output (file descriptor 1).
[x]
>
[x]
>>
[x]
<
[ ]
|
[x]
<Word
Uses the file specified by the Word parameter as standard input (file descriptor 0).[x]
>Word
Uses the file specified by the Word parameter as standard output (file descriptor 1). If the file does not exist, the shell creates it. If the file exists and the noclobber option is on, an error results; otherwise, the file is truncated to zero length. Note: When multiple shells have the noclobber option set and they redirect output to the same file, there could be a race condition, which might result in more than one of these shell processes writing to the file. The shell does not detect or prevent such race conditions.[ ]
>|Word
Same as the >Word command, except that this redirection statement overrides the noclobber option.[x]
>>Word
Uses the file specified by the Word parameter as standard output. If the file currently exists, the shell appends the output to it (by first seeking the end-of-file character). If the file does not exist, the shell creates it.[ ]
~~<>Word
Opens the file specified by the Word parameter for reading and writing as standard input.[ ]
<<[-]Word
Reads each line of shell input until it locates a line containing only the value of the Word parameter or an end-of-file character. The shell does not perform parameter substitution, command substitution, or file name substitution on the file specified. The resulting document, called a here document, becomes the standard input. If any character of the Word parameter is quoted, no interpretation is placed upon the characters of the document.[x]
<&Digit
Duplicates standard input from the file descriptor specified by the Digit parameter[x]
>& Digit
Duplicates standard output in the file descriptor specified by the Digit parameter[x]
<&-
Closes standard input[x]
>&-
Closes standard output[ ]
~~<&p
Moves input from the co-process to standard input[ ]
~~>&p
Moves output to the co-process to standard output[x]
[n]>>word
where the optional n represents the file descriptor number. If the number is omitted, the redirection refers to standard output (file descriptor 1).http://www.ibm.com/support/knowledgecenter/ssw_aix_72/com.ibm.aix.osdevice/korn_shell_inout_redir.htm
http://pubs.opengroup.org/onlinepubs/007904875/utilities/xcu_chap02.html#tag_02_07