Infodayne Infodayne - 5 months ago 29
Bash Question

Call script A from script B, and write output of script A to file

I have two scripts, A and B.

I need to capture all the terminal output from script A into a file. I know that I can do this:

A |tee myfile.log
, or
A > myfile.log

However, when I do it from script B, it doesn't work (script A runs fine but output not redirected).

Ex. Script A:

echo "I'm script A"

Ex. Script B:

echo "Starting script B"
A |tee myfile.log
echo "Finished script B"



I'm script A


This seems to work well enough for me. You need ./ because script 'a' is not in your $PATH. The ./ says 'look in the current directory for my script rather than looking at all the directories specified in $PATH'.

echo "Starting script B"
./ | tee myfile.log
echo "Finished script B"