zsh shell script subscript redirect output to terminal and log file

Viewed 19

I have a situation where I have a master shell script (in zsh) which calls other scripts to facilitate a process. What I would like is to have the output of my subscripts to be piped to terminal shell and a log file.

Master Script:

./run_script1.sh >&1 log1.txt 2>&1
./run_script2.sh >&1 log2.txt 2>&1

But when executing I don't get anything on terminal from the output of the other scripts, it only appears in the log file.

1 Answers

It's been a while since I've used zsh, so I'm not sure whether what you tried makes sense or not.

However, the standard way to send output to both stdout and to a separate file is with the tee Unix command.

So you probably want something like

./run_script1.sh 2>&1 | tee log1.txt
./run_script2.sh 2>&1 | tee log2.txt
Related