How to redirect command output to variable and console same time.
Example:
var=`ls -l`
I want to print output in console at the same time and not later "echo $var"
How to redirect command output to variable and console same time.
Example:
var=`ls -l`
I want to print output in console at the same time and not later "echo $var"
var=$(ls -l | tee /dev/stderr)
Note that this is assumed to just be an example -- you should never use ls
in scripts, except where the output will only be consumed by human readers.
You're looking for the tee command.
DESCRIPTION
Copy standard input to each FILE, and also to standard output.