K
K
koxac2020-02-08 22:54:52
linux
koxac, 2020-02-08 22:54:52

How to display and write to a variable?

There is a code

echo step 1 && sleep 5 && echo step 2 && sleep 5 && echo step 3 && sleep 5 && echo finish


To store the result in a variable, do this
res=`echo step 1 && sleep 5 && echo step 2 && sleep 5 && echo step 3 && sleep 5 && echo finish`
echo $res;


But then it will be displayed on the screen only upon completion, but how to make it so that it is displayed in the process of work and upon completion there is a variable with the result?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2020-02-09
@koxac

koxac , Treated by putting brackets around everything

(echo step 1 && sleep 5 && echo step 2 ) | tee /tmp/a.log

res=$(cat /tmp/a.log)
echo $resstep 1 step 2
5e401c6dc9ba9785453481.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question