Re: [SLE] BASH History

From: Danny Sauer (suse-linux-e.suselists_at_danny.teleologic.net)
Date: 09/01/04

  • Next message: Danny Sauer: "Re: [SLE] Will SuSE 9.2 contain the gatos (radeon AIW TV playback/recording) drivers?"
    Date: Wed, 1 Sep 2004 16:58:52 -0500
    To: SuSE List <suse-linux-e@suse.com>
    
    

    Randall wrote regarding '[SLE] BASH History' on Sat, Aug 28 at 10:07:
    > Hi,
    >
    > The BASH history question reminded of a small problem I have with this
    > function that perhaps someone can help me with.
    >
    > I always keep a Konsole window open in which I have four regular
    > interactive BASH shells and one root shell running.
    >
    > When I log out or shut down, it seems that the four shells running under
    > my user ID clash somehow or fail to coordinate in the way they write the
    > history file, and I end up with only one of those shells' history.
    >
    > Does anyone know of a way to get all four shells' worth of history saved?

    Well, the problem here is described in the bash man page. I know, I know,
    man pages are too complicated for mere mortals to read (that's the gist I
    get from the list recently). So, as I consider myself well above mere
    mortal status, let me copy and paste. :)

     On startup, the history is initialized from the file named
     by the variable HISTFILE (default ~/.bash_history). The
     file named by the value of HISTFILE is truncated, if nec­
     essary, to contain no more than the number of lines speci­
     fied by the value of HISTFILESIZE. When an interactive
     shell exits, the last $HISTSIZE lines are copied from the
     history list to $HISTFILE. If the histappend shell option
     is enabled (see the description of shopt under SHELL
     BUILTIN COMMANDS below), the lines are appended to the
     history file, otherwise the history file is overwritten.
     If HISTFILE is unset, or if the history file is
     unwritable, the history is not saved. After saving the
     history, the history file is truncated to contain no more
     than HISTFILESIZE lines. If HISTFILESIZE is not set, no
     truncation is performed.
     
    In the reading of that section, it becomes clear what's happening. Each
    of the shells that your kterm starts reads the history file when it starts
    up. Then, it stores the commands in memory until it exits. At the time
    of exit, it creates a new history file containing the last 500 entries in
    memory. What you have is 4 shells that have the same last 500 lines when
    they start, but then each one adds only to its in-memory list. The lines
    that are saved, therefore, can only be those that are in the list of the
    last one to exit, and it has no idea what the other shells might have put in
    the file when they exited.

    If you want to solve that problem, the one possible "reliable" solution
    is to make the history file a named pipe, and run a daemon that manages
    sorting duplicates, etc. That wouldn't be *too* hard to write, but would
    be a pain none the less. You could play with the "shopt" builtin to
    change the history's features (or change variables before startup). The
    first thing that comes to mind is that you could set "histappend" so that
    each shell appends to the end of the existing history file rather than
    overwriting it. That would very likely save you, as the shell should
    append then truncate, and the other exiting shells (they do exit when you
    log out) would respect the file lock placed on the file when it's being
    manipulated by each shell in succession.

    put a line that says
            shopt -s histappend
    at the top of your .profile / .bashrc and see if that helps. Turn on
    the "cdspell" option, too. It's cool. 'shopt -s cdspell'

    --Danny, who misspells stuff regularly :)

    -- 
    Check the headers for your unsubscription address
    For additional commands send e-mail to suse-linux-e-help@suse.com
    Also check the archives at http://lists.suse.com
    Please read the FAQs: suse-linux-e-faq@suse.com
    

  • Next message: Danny Sauer: "Re: [SLE] Will SuSE 9.2 contain the gatos (radeon AIW TV playback/recording) drivers?"

    Relevant Pages

    • Re: Common History across Shell
      ... Note the history of your session won't be ... When the shell starts up, the history is initialized from the file ... named by the value of HISTFILE is truncated, if necessary, to contain ... Builtin Commands), the lines are appended to the history file, ...
      (comp.unix.shell)
    • Re: [SLE] BASH History
      ... > The BASH history question reminded of a small problem I have with this ... > interactive BASH shells and one root shell running. ... > history file, and I end up with only one of those shells' history. ... Perhaps the history is only saved if you logout of each shell properly, ...
      (SuSE)
    • Re: Common History across Shell
      ... maintains its individual history in memory. ... If there are multiple shells running together then commands entered in ... one can't be accessed using history command from other shells. ... Does such a feature exist in bash or any other shell? ...
      (comp.unix.shell)
    • Re: Common History across Shell
      ... maintains its individual history in memory. ... As and when a bash session ... one can't be accessed using history command from other shells. ... I am looking for a feature where if a user has multiple shells and on ...
      (comp.unix.shell)
    • Re: [SLE] BASH History
      ... On Saturday 28 Aug 2004 16:07, Randall R Schulz wrote: ... > The BASH history question reminded of a small problem I have with this ... > interactive BASH shells and one root shell running. ... > history file, and I end up with only one of those shells' history. ...
      (SuSE)