Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #266941

Re: script/history

From Michael Grant <mgrant@grant.org>
Newsgroups linux.debian.user
Subject Re: script/history
Date 2024-02-04 12:30 +0100
Message-ID <I3IRe-7OGZ-9@gated-at.bofh.it> (permalink)
References <I3Hip-7Nv9-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

> $ 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

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

script/history "Gareth Evans" <donotspam@fastmail.fm> - 2024-02-04 10:50 +0100
  Re: script/history hw <hw@adminart.net> - 2024-02-04 12:20 +0100
  Re: script/history Michael Grant <mgrant@grant.org> - 2024-02-04 12:30 +0100
    Re: script/history "Gareth Evans" <donotspam@fastmail.fm> - 2024-02-04 14:20 +0100
    Re: script/history hw <hw@adminart.net> - 2024-02-04 14:30 +0100
  Re: script/history Greg Wooledge <greg@wooledge.org> - 2024-02-04 14:30 +0100
  Re: script/history Max Nikulin <manikulin@gmail.com> - 2024-02-04 14:30 +0100
    Re: script/history "Gareth Evans" <donotspam@fastmail.fm> - 2024-02-04 17:10 +0100
      Re: script/history Greg Wooledge <greg@wooledge.org> - 2024-02-04 18:40 +0100
        Re: script/history "Gareth Evans" <donotspam@fastmail.fm> - 2024-02-05 01:30 +0100
          Re: script/history Greg Wooledge <greg@wooledge.org> - 2024-02-05 01:50 +0100
            Re: script/history "Gareth Evans" <donotspam@fastmail.fm> - 2024-02-05 02:30 +0100
      Re: script/history David Wright <deblis@lionunicorn.co.uk> - 2024-02-04 20:50 +0100
        Re: script/history Greg Wooledge <greg@wooledge.org> - 2024-02-04 21:40 +0100
        Re: script/history "Gareth Evans" <donotspam@fastmail.fm> - 2024-02-05 01:40 +0100
  Re: script/history Will Mengarini <seldon@eskimo.com> - 2024-02-05 02:20 +0100

csiph-web