Oh you're right, I entirely overlooked the usage of 'script' and didn't understand the question right, sorry.
On Sun, 2024-02-04 at 06:28 -0500, Michael Grant wrote: > > $ script foo.txt > > Script started, output log file is 'foo.txt'. > > $ date > > Sun 4 Feb 09:44:00 GMT 2024 > > $ exit > > exit > > Script done. > > $ history|tail -n2 > > 30797 2024-02-04 09:43:57 script foo.txt > > 30798 2024-02-04 09:44:21 history|tail -n2 > > > > I did try to search on this but just got lots of "bash history" and > > "history in > > bash script" references. > > So this might surprise you but the commands are actually in the > history list! But not in the current shell. > > What happens is this: > > You start 'script foo.txt' and this starts a sub bash shell on a > different pseudo tty. You run some commands, it appends each command > to the history of this sub-shell's history. > > You then exit your script. Those commands you ran are at the bottom > of .bash_history (try to cat that file out after you exit script and > you should see them). > > But those commands are not sucked into the history of your current > shell. Then, you log out (or exit) your current shell and the history > of that shell overwrites the history of the previous one. > > If all you want to do is save off the commands after you exit your > script session, then simply move or copy .bash_history out of the way > before it gets overwritten. > > You might consider setting $HISTFILE to some other location other than > .bash_history. > > Michael Grant