How to store the output of a command in a variable at the same time as printing the output?

Use tee to direct it straight to screen instead of stdout

$ var=$(echo hi | tee /dev/tty)
hi
$ echo $var
hi

Leave a Comment