Display output of a Bash command and keeping the output in a variable

Selmak picture Selmak · Jan 17, 2010 · Viewed 13.9k times · Source

I'm not sure if it is possible but what I want to do is to run a bash command and storing the output in a variable AND display it as if I launched the command normally. Here is my code:

VAR=`svn checkout $URL`

So I want to store the output in VAR and still see the result (and because svn checkout takes a long time, I can't do echo $VAR just after..)

Thanks

Answer

Alok Singhal picture Alok Singhal · Jan 17, 2010

If the command is run from a terminal, you can do:

VAR=$(svn checkout $URL | tee /dev/tty)