求解惑,Linux管道和重定向最近看到一篇关于管道的文章中有这样的描述:alias testcmdcommand ls -ld / xx
求解惑,Linux管道和重定向 最近看到一篇关于管道的文章中有这样的描述:
alias testcmd='command ls -ld / xxx ~/.bashrc yyy' # swap stdout & stderr stream, i.e. # let the stderr stream pass through a pipe while the stdout is printed to the terminal only # cf. http://tldp.org/LDP/abs/html/io-redirection.html: # "Child processes inherit open file descriptors. This is why pipes work. # To prevent an fd from being inherited, close it." ( exec 3>&1 testcmd 2>&1 1>&3 3>&- | tr '[[:lower:]]' '[[:upper:]]' 3>&- exec 3>&- )
在我的RHEL上输出是这样的: drwxr-xr-x 26 root root 4096 Oct 7 22:37 / -rw-r--r-- 1 admin root 497 Aug 14 14:31 /home/admin/.bashrc LS: XXX: NO SUCH FILE OR DIRECTORY LS: YYY: NO SUCH FILE OR DIRECTORY