Is there a way to append the stdout output of one command to another’s and pipe the combined output to another command? I used to use the following approach(taking ack-grep as an example)
# List all python, js files in different directories
ack-grep -f --py apps/ > temp
ack-grep -f --js -f media/js >> temp
cat temp | xargs somecommand
Is there a way to do this in a single command?
Just run the two
ack-grepcommands as a compound command; then pipe the results of the compund command. The first compound command defined inman bashis the parentheses:So:
You can use curly braces to similar effect, but curly braces have a few syntactical differences (they’re more finicky about needing spaces between the brace and other words, for instance). The biggest difference is that the commands inside braces are run in the current shell environment, so they can impact on your environment. For instance:
If you want to get really fancy you can define a function and execute that: