I've often wanted to log the output of Terminal. So I tried to set script
to run at startup; in my .bashrc file I put:
script ~/Logs/$(date "+%Y-%m-%d.%H-%M-%S")
Because the commands in my .bashrc file are run whenever I open an interactive terminal, I thought this would do what I wanted.
However, because script
itself opens a new terminal during the course of its execution, I instead ended up with a fork bomb:
Last login: Sat May 9 12:02:43 on ttys001
Script started, output file is /Users/mchenja/Logs/2015-05-09.12-14-37
Script started, output file is /Users/mchenja/Logs/2015-05-09.12-14-37
Script started, output file is /Users/mchenja/Logs/2015-05-09.12-14-37
Script started, output file is /Users/mchenja/Logs/2015-05-09.12-14-37
Script started, output file is /Users/mchenja/Logs/2015-05-09.12-14-37
Script started, output file is /Users/mchenja/Logs/2015-05-09.12-14-37
[mchenja@mycomp ~]$
Any tips on how to ensure that script
is run exactly once when I open a new interactive terminal?
If it matters, this is on OS X, although I believe the same thing would happen in Linux.