1

Then I call command in my bash script like command it's outputs to my terminal but isn't saving anywhere. If I want to save output I use output=$(command) but now command output isn't showing to my screen unless command would be completed so I can call echo "${output}". But the problem is: I don't want to wait until command will be completed. So, is there any way to call command, show output while it's running and later save everything to a variable?

It could work, if I call it twice:

command
output=$(command)

but it's not that good I think.

sry for my engrish.

Demiler
  • 67
  • 3
  • 9

1 Answers1

1

I think you want a tool called tee:

The tee utility copies standard input to standard output, making a copy in zero or more files. The output is unbuffered.

It will output to the screen and also to a file. you use it like this:

cat file1.txt | tee -a file2.txt

Use of cat is just an example. Any command on the left side of the pipe should work.

Z4-tier
  • 7,287
  • 3
  • 26
  • 42
  • 2
    `output=$(command | tee /dev/fd/2)` is more appropriate; the OP isn't indicating anywhere that they want to save to a file. – Charles Duffy Nov 25 '19 at 16:06
  • 1
    Also, questions that already exist in the knowledgebase should be flagged as duplicate, not answered; that way folks get the most complete answers possible, already vetted/edited/amended/etc. If the answers on an existing duplicate aren't as good as what you'd write yourself, flag-as-duplicate and add your answer on that prospective duplicate itself. – Charles Duffy Nov 25 '19 at 16:06
  • Charles duffy, thanks. That is definitely what I've needed. – Demiler Nov 25 '19 at 16:10