How to display and write to a variable?

There is a code
step echo 1 && sleep 5 && echo step 2 && sleep 5 && echo step 3 && sleep 5 && echo finish


To write the result to a variable do so
res=`echo step 1 && sleep 5 && echo step 2 && sleep 5 && echo step 3 && sleep 5 && echo finish`
echo $res;


But then the screen will be printed only on completion, but how to do so derived in the process and upon completion was the variable with the result?
April 7th 20 at 10:44
2 answers
April 7th 20 at 10:46
Solution
@julia_Stracke46, Treated in the formulation of parentheses around the whole

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

res=$(cat /tmp/a.log)
echo $resstep 1 step 2
5e401c6dc9ba9785453481.png
April 7th 20 at 10:48
res=$(step 1) && echo $res && sleep 5 && res="$res $(step 2)" && echo $rest ...


But it is a bit nonsense. Do not write megatronic, just write a script or function.
does not fit, the team I for example wrote, there the script will run few minutes and it is necessary that it deduced a result in the process and that the variable remained the result - julia_Stracke46 commented on April 7th 20 at 10:51
What doesn't?
You the task describe.
If you want the script output something along the way, then edit the script itself. It's logical, damn that team around the script cannot be executed while running the script. - andy.Stark commented on April 7th 20 at 10:54
@julia_Stracke46

step echo 1 && sleep 5 && echo step 2 && sleep 5 && echo step 3 && sleep 5 && echo finish | tee /tmp/a.log
res=$(cat /tmp/a.log)
- Jalyn49 commented on April 7th 20 at 10:57
@Jalyn49,
you have to tee will only echo finish - andy.Stark commented on April 7th 20 at 11:00
@Jalyn49, @andy.Stark, well, then
step echo 1 | tee /tmp/a1.log && sleep 5 && echo step 2 | tee /tmp/a2.log && sleep 5 && echo step 3 | tee /tmp/a3.log && sleep 5 && echo finish | tee /tmp/a.log && res=$(cat /tmp/a1.log /tmp/a2.log /tmp/a3.log /tmp/a.log) && echo $res
while I agree that this is nonsense, a crutch ad hoc. - Shanny_Greenfelder commented on April 7th 20 at 11:03
@andy.Stark, yeah right treated in the formulation of parentheses around the whole

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

cat /tmp/a.log
step 1
step 2
- Jalyn49 commented on April 7th 20 at 11:06
@Jalyn49, thank you, what you need

@andy.Stark, though about any team, just wanted to understand whether, and to display and save the result into a variable, take that same browser is launched through the console - julia_Stracke46 commented on April 7th 20 at 11:09
@julia_Stracke46, mark as solution please - Jalyn49 commented on April 7th 20 at 11:12

Find more questions by tags LinuxbashCommand line