Input/Output Before a command is executed, its input and output may be redirected using a special notation interpreted by the shell. The following may appear anywhere in a simple-command or may precede or follow a command and are not passed on to the invoked command. Command substitution, parameter expansion, and arithmetic substitution occur before word or digit is used except as noted below. File name generation occurs only if the shell is interactive and the pattern matches a single file. Field splitting is not performed. In each of the following redirections, if file is of the form /dev/tcp/host/port, or /dev/udp/host/port, where host is a hostname or host address, and port is an integer port number, then the redirection attempts to make a tcp or udp connection to the corresponding socket. <word | Use file word as standard input (file descriptor 0). | >word | Use file word as standard output (file descriptor 1). If the file does not exist then it is created. If the file exists, and the noclobber option is on, this causes an error; otherwise, it is truncated to zero length. | >|word | Same as >, except that it overrides the noclobber option. | >>word | Use file word as standard output. If the file exists then output is appended to it (by first seeking to the end-of-file); otherwise, the file is created. | <>word | Open file word for reading and writing as standard input. | <<[ ]word | The Korn shell input is read up to a line that is the same as word, or to an end-of-file. No parameter substitution, command substitution or file name generation is performed on word. The resulting document, called a here-document, becomes the standard input. If any character of word is quoted, then no interpretation is placed upon the characters of the document; otherwise, parameter and command substitution occurs, \new-line is ignored, and \ must be used to quote the characters \, $, `, and the first character of word. If ?is appended to <<, then all leading tabs are stripped from word and from the document. | <&digit | The standard input is duplicated from file descriptor digit (see dup(2)). Similarly for the standard output using >& digit. | <&?/P> | The standard input is closed. Similarly for the standard output using >&?/span>. | <&p | The input from the co-process is moved to standard input. | >&p | The output to the co-process is moved to standard output. | If one of the above is preceded by a digit, then the file descriptor number referred to is that specified by the digit (instead of the default 0 or 1). For example: ... 2>&1 means file descriptor 2 is to be opened for writing as a duplicate of file descriptor 1. The order in which redirections are specified is significant. The Korn shell evaluates each redirection in terms of the file descriptor/file association at the time of evaluation. For example: ... 1 >fname 2>&1 first associates file descriptor 1 with file fname. It then associates file descriptor 2 with the file associated with file descriptor 1 (i.e. fname). If the order of redirections were reversed, file descriptor 2 would be associated with the terminal (assuming file descriptor 1 had been) and then file descriptor 1 would be associated with file fname. If a command is followed by & and job control is not active, then the default standard input for the command is the empty file /dev/null. Otherwise, the environment for the execution of a command contains the file descriptors of the invoking shell as modified by input/output specifications. |