Reputation: 141
I saw in a previous question that putting exec > >(tee -ai file)
will capture every thing that is displayed in the script while still showing it. This works but, being able to just "snap-shot" whats displayed in the terminal with out recording it all the time would work better
Upvotes: 1
Views: 483
Reputation: 3816
Three things you can do here:
you can simple set the output to a file like:
bash printer.sh > saving_file
Note: if you already have a file called saving_file from the previous session use >> (append the new output to the existing file without overwriting the existing data) instead of > (will overwrite anything stored previously will be lost)
you can use nohup:
nohup bash printer.sh
both of these commands will save everything that is output of the script.
Third thing you can do is you can just make use of the script
command, simply do a:
script saving_file
so whatever you will do in your terminal after the script command will be saved to a file called saving_file. if you want to stop sending everything from the terminal simply do an exit
and you will be using terminal normally.
you can use nohup and writing to a file from within a shell script as well, if you are asking for something other than that then I will recommend using something like the following code.
var=$(echo 'hello world')
echo $var > saving_file # this will write 'hello world' to a file named saving _file
echo $var # this will display hello world
Upvotes: 3