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