Friday, December 4, 2009

I/O Redirection








 

 










I/O Redirection



When scanning the command line, the shell looks for the special redirection characters < and >. If found, they are processed and removed (with any associated arguments) from the command line. Table A.7 summarizes the different types of I/O redirection that the shell supports.





































































































Table A.7. I/0 Redirection


Construct





Meaning





< file





Redirect standard input from file.





> file





Redirect standard output to file; file is created if it doesn't exist and zeroed if it does.





>| file





Redirect standard output to file; file is created if it doesn't exist and zeroed if it does; the noclobber (-C) option to set is ignored.





>> file





Like >, only output is appended to file if it already exists.





<< word





Redirect standard input from lines that follow up until a line containing just word; parameter substitution occurs on the lines, and back-quoted commands are executed and the backslash character interpreted; if any character in word is quoted, none of this processing occurs and the lines are passed through unaltered; if word is preceded by a -, leading tabs on the lines are removed.





<& digit





Standard input is redirected from the file associated with file descriptor digit.





>& digit





Standard output is redirected to the file associated with file descriptor digit.





<&-





Standard input is closed.





>&-





Standard output is closed.





<> file





Open file for both reading and writing.





Note that filename substitution is not performed on file. Any of the constructs listed in the first column of the table may be preceded by a file descriptor number to have the same effect on the file associated with that file descriptor.



The file descriptor 0 is associated with standard input, 1 with standard output, and 2 with standard error.












     

     


    No comments: