7

I am running a script called upgrade.sh

ANd upgrade.sh calls a script called roll.sh

roll.sh >> logfile.text

But roll.sh has some questions and prompts, and the redirect is preventing those outputs from hitting the screen. I cannot edit roll.sh.

I also tried `results=$(roll.sh)

Even then, the output was not coming onto the screen

roymustang86
  • 8,054
  • 22
  • 70
  • 101

3 Answers3

15

Use tee, it was created specifically for this purpose: to forward standard input to the screen and one or more files. Make sure to use the -a option to append to logfile.text if you don't want to overwrite it.

roll.sh | tee -a logfile.text
Cory Klein
  • 51,188
  • 43
  • 183
  • 243
  • 3
    The only thing that I would add is that you should probably do ```roll.sh 2>&1 | tee -a logfile.txt``` to also capture error output – Srdjan Grubor Feb 17 '13 at 19:18
1

You want tee:

TEE(1)                           User Commands                          TEE(1)



NAME
       tee - read from standard input and write to standard output and files
evil otto
  • 10,348
  • 25
  • 38
1

A common way to handle that is to have the script write its prompts to stderr instead of stdout.

William Pursell
  • 204,365
  • 48
  • 270
  • 300