Regex 在bash中重用管道命令

Regex 在bash中重用管道命令,regex,linux,bash,shell,sed,Regex,Linux,Bash,Shell,Sed,我使用以下命令缩进配置脚本的输出: ./configure | sed "s/^/ /" 现在我想重用管道后面的部分,这样我就不必写了 ./configure | sed "s/^/ /" make | sed "s/^/ /" make install | sed "s/^/ /" 我尝试将sed放入如下变量: indent=sed "s/^/ /" 然后呢 ./configure | indent 但这不起作用-我如何实现这一点?使用BASH数组保存se

我使用以下命令缩进配置脚本的输出:

./configure | sed "s/^/    /"
现在我想重用管道后面的部分,这样我就不必写了

./configure | sed "s/^/    /"
make | sed "s/^/    /"
make install | sed "s/^/    /"
我尝试将
sed
放入如下变量:

indent=sed "s/^/    /"
然后呢

./configure | indent

但这不起作用-我如何实现这一点?

使用BASH数组保存sed命令:

indent=(sed "s/^/    /")
indent() { sed "s/^/    /"; }
然后使用:

./configure | "${indent[@]}"
make | "${indent[@]}"
make install | "${indent[@]}"
./configure | indent
make | indent
make install | indent
或者使用此sed命令的函数:

indent=(sed "s/^/    /")
indent() { sed "s/^/    /"; }
然后使用:

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

为什么不把它当作别名呢

alias indent="sed 's/^/    /'"
试试这个:

(./configure; make; make install) | sed "s/^/    /"

+1.两条注释:在当前shell中使用
{list;}
;用
&
而不是
分隔命令短路以防故障。我同意你的看法。谢谢两个提示。对,我的偏好也是函数,只是想展示另一种方法。但是的,我应该把功能部分放在上面。