From 8844f0c142ade7d6dfea20fc65432b4f97fb92c9 Mon Sep 17 00:00:00 2001 From: David Adam Date: Sun, 3 Aug 2014 18:45:03 +0800 Subject: [PATCH] Clarify I/O redirection documentation Fix the examples and try and improve the clarity of the section. Closes #1409. --- doc_src/index.hdr.in | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in index 758a597b8..a71bae4a1 100644 --- a/doc_src/index.hdr.in +++ b/doc_src/index.hdr.in @@ -168,16 +168,16 @@ default through a simple mechanism called a redirection. An example of a file redirection is echo hello \>output.txt, which directs the output of the echo command to the file output.txt. -- To redirect standard input, write \ -- To redirect standard output, write \>DESTINATION -- To redirect standard error, write ^DESTINATION -- To redirect standard output to a file which will be appended, write \>\>DESTINATION_FILE -- To redirect standard error to a file which will be appended, write ^^DESTINATION_FILE +- To read standard input from a file, write \ +- To write standard output to a file, write \>DESTINATION +- To write standard error to a file, write ^DESTINATION +- To append standard output to a file, write \>\>DESTINATION_FILE +- To append standard error to a file, write ^^DESTINATION_FILE DESTINATION can be one of the following: - A filename. The output will be written to the specified file. -- An ampersand (\&) followed by the number of another file descriptor. The file descriptor will be a duplicate of the specified file descriptor. +- An ampersand (\&) followed by the number of another file descriptor. The output will be written to that file descriptor instead. - An ampersand followed by a minus sign (\&-). The file descriptor will be closed. Example: @@ -186,15 +186,16 @@ To redirect both standard output and standard error to the file all_output.txt, you can write echo Hello \>all_output.txt ^\&1. -Any FD can be redirected in an arbitrary way by prefixing the -redirection with the number of the FD. +Any file descriptor can be redirected in an arbitrary way by prefixing the +redirection with the file descriptor. -- To redirect input of FD number N, write N\ -- To redirect output of FD number N, write N\>DESTINATION -- To redirect output of FD number N to a file which will be appended, write N\>\>DESTINATION_FILE +- To redirect input of FD N, write N\ +- To redirect output of FD N, write N\>DESTINATION +- To append the output of FD N to a file, write N\>\>DESTINATION_FILE -Example: echo Hello 2\>- and echo Hello ^- are -equivalent. +Example: echo Hello 2\>output.stderr and echo Hello +^output.stderr are equivalent, and write the standard error (file +descriptor 2) of the target program to output.stderr. \subsection piping Piping