重定向顺序[重复]


1

有什么区别:

命令>文件名2>& 1

命令2>& 1>文件名

为什么例如(假设没有 xxx 文件)。

ls xxx> 1.txt 2>& 1

同时工作

ls xxx 2>& 1> 1.TXT

不?


有一个很好的插图教程 图解重定向教程 这让所有这些都更容易理解
DavidPostill

Answers:


1

重定向的顺序很重要。例如,命令

ls > dirlist 2>&1

在命令的同时,将标准输出(文件描述符1)和标准错误(文件描述符2)指向文件dirlist

ls 2>&1 > dirlist

仅将标准输出指向文件dirlist,因为标准错误在标准输出重定向到dirlist之前成为标准输出的副本。

(引自 Bash参考手册

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.