我有个bash功能:
zmx () {
"$@" 2> >( while read line; do echo -e "r2g: $line"; done ) > \
>( while read line; do echo -e "r2g: $line"; done )
}它所做的是将"r2g:“附加到stdout/stderr的每一行。
你就这样用它:
$ zmx echo "foo"你会得到:
r2g: foo它在Bash4中工作得很好,但在Mac上运行时,它似乎与Bash3不同。
有人知道如何将其转换为惯用的Bash3吗?
发布于 2018-07-07 00:47:15
关于bash 3.2.57的工作
MacBook-Pro:~ em$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.
MacBook-Pro:~ em$ zmx() { "$@" 2> >(while read line;do echo -e "err: $line"; done ) > >(while read line; do echo -e "std: $line"; done); }
MacBook-Pro:~ em$ zmx bash -c "ls -1 /etc/ | head -5 ; cat /etc/shadow"
std: afpovertcp.cfg
std: afpovertcp.cfg~orig
std: aliases
std: aliases.db
std: apache2
err: cat: /etc/shadow: No such file or directoryhttps://unix.stackexchange.com/questions/453963
复制相似问题