Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 978 Bytes

bash-io-redirection.org

File metadata and controls

31 lines (23 loc) · 978 Bytes

bash io redirection

基于文件描述符的 I/O 重定向:

M>N
  # "M" is a file descriptor, which defaults to 1, if not explicitly set.
  # "N" is a filename.
  # File descriptor "M" is redirect to file "N."
M>&N
  # "M" is a file descriptor, which defaults to 1, if not set.
  # "N" is another file descriptor.

顺序问题:

Note that the order of redirections is significant. For example, the command

ls > dirlist 2>&1

directs both standard output (file descriptor 1) and standard error (file descriptor 2) to the file dirlist, while the command

ls 2>&1 > dirlist

directs only the standard output to file dirlist, because the standard error was made a copy of the standard output before the standard output was redirected to dirlist.

参考:I/O Redirection