Skip to main content

Capture the command STDOUT to a variable and re-use it as many times as you like:

commandoutput=$commandoutput="$(command-to-run)" echo $commandoutput"$commandoutput" | grep -i errors echo $commandoutput"$commandoutput" | pbcopy 

If you need to capture STDERR too, then use 2>&1 at the end of the command, like so:

commandoutput=$commandoutput="$(command-to-run 2>&1)" 

Capture the command STDOUT to a variable and re-use it as many times as you like:

commandoutput=$(command-to-run) echo $commandoutput | grep -i errors echo $commandoutput | pbcopy 

If you need to capture STDERR too, then use 2>&1 at the end of the command, like so:

commandoutput=$(command-to-run 2>&1) 

Capture the command STDOUT to a variable and re-use it as many times as you like:

commandoutput="$(command-to-run)" echo "$commandoutput" | grep -i errors echo "$commandoutput" | pbcopy 

If you need to capture STDERR too, then use 2>&1 at the end of the command, like so:

commandoutput="$(command-to-run 2>&1)" 
Source Link
laebshade
  • 2.2k
  • 15
  • 17

Capture the command STDOUT to a variable and re-use it as many times as you like:

commandoutput=$(command-to-run) echo $commandoutput | grep -i errors echo $commandoutput | pbcopy 

If you need to capture STDERR too, then use 2>&1 at the end of the command, like so:

commandoutput=$(command-to-run 2>&1)