微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux – 在bash中重用命令管道

我使用以下内容来缩进configure脚本的输出

./configure | sed "s/^/    /"

现在我想重用管道后面的部分,所以我不必写

./configure | sed "s/^/    /"
make | sed "s/^/    /"
make install | sed "s/^/    /"

我试图将sed放在这样的变量中:

indent=sed "s/^/    /"

然后呢

./configure | indent

但那不起作用 – 我怎样才能做到这一点?

解决方法:

使用BASH数组来保存sed命令:

indent=(sed "s/^/    /")

然后使用:

./configure | "${indent[@]}"
make | "${indent[@]}"
make install | "${indent[@]}"

或者使用此sed命令的函数

indent() { sed "s/^/    /"; }

然后使用:

./configure | indent
make | indent
make install | indent

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐