I have a bash script that calls various commands and prints some output (both from the called commands themselves, such as git pull
, and informative messages generated by the script itself such as Operation took XX minutes
.
I'd like to capture the whole output to a file from the script itself: basically I'm trying to avoid the need to call ./myscript.sh | tee file.txt
for non-relevant-here reasons.
Basically I'd like to do something like this:
startCapture
git pull
echo "Text"
other-command
endCapture
I also require the output to be printed on my shell while the script is running.
The final goal is to:
- run
./myscript.sh
without additional shell constructs - see the output on the terminal as I do now
- obtain a file on disk with the whole output
Is this even possible?