Reuse command to connect in bash

I am using the following to indent the output of the configure script:

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

      

Now I want to reuse part by pipe, so I don't have to write

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

      

I tried to put sed

in a variable like this:

indent=sed "s/^/    /"

      

and then do

./configure | indent

      

but it didn't work - how can i achieve this?

+3


source to share


3 answers


Use a BASH array to store the sed command:

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

      

Then use:

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

      



OR otherwise use the function for this sed command:

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

      

Then use:

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

      

+7


source


Try the following:



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

      

+3


source


Why not just make a nickname?

alias indent="sed 's/^/    /'"

      

+2


source







All Articles