20

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

2 Answers 2

26

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

VAR=$(svn checkout $URL | tee /dev/tty)
Sign up to request clarification or add additional context in comments.

3 Comments

Gah, beat me to it by seconds!
Maybe because I tested the above with v=$(for i in $(seq 20); do echo $i; sleep 0.2; done | tee /dev/tty), and you used sleep 1? :-)
Note that this does not work when executed by Github Actions due to the lack of a tty (see github.com/actions/runner/issues/241 )
2

You don't have to call the external tee:

VAR=$(svn checkout $URL) && echo $VAR

or even:

VAR=$(svn checkout $URL); echo $VAR

2 Comments

I think the idea was that svn takes a long time, and the OP wanted to see the output of the svn command in realtime, instead of after it ended. He even says so in the question :-)
I think I need to get some help on literacyoverflow!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.