Say I want to echo
something and capture it in a variable, at the same time I see it in my screen.
echo "hello" | tee tmp_file
var=$(< tmp_file)
So now I could see hello
in my terminal as well as saving it into the variable $var
.
However, is there any way to do this without having to use a temporary file? tee
doesn't seem to be the solution, since it says (from man tee
) read from standard input and write to standard output and files, whereas here it is two times standard output.
I am in Bash 4.3, if this matters.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…