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


Groups > gnu.bash.bug > #15310

Re: History not saved when closing terminal while bash is sourcing a script

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: History not saved when closing terminal while bash is sourcing a script
Date 2019-08-08 08:35 -0400
Message-ID <mailman.1056.1565267735.1985.bug-bash@gnu.org> (permalink)
References <20190803150529.u5lf2tzvgo5sie7m@nomi.cz> <2b96a07b-c679-ea90-a714-056c81ee0c97@case.edu> <20190808081335.vlcr2ele27hoogue@nomi.cz> <d0fc69f3-38ba-4109-d077-9799eb2ddcee@case.edu>

Show all headers | View raw


On 8/8/19 4:13 AM, Tomas Janousek wrote:
> Hi,
> 
> On Sun, Aug 04, 2019 at 01:42:12PM -0400, Chet Ramey wrote:
>> On 8/3/19 11:05 AM, Tomas Janousek wrote:
>> I don't have or use tmux, but I'm going to guess that `kill-window' sends
>> a SIGHUP to the process group and follows it up with a SIGKILL. The
>> `source' turns off saving to history -- the `source' gets saved in the
>> history list, not the commands it runs -- and is still running when the
>> SIGHUP arrives. The SIGHUP causes the shell to exit without saving the
>> history because history is turned off when the signal handler runs.
> 
> So this means `source' shouldn't ever be used in interactive shells if one
> cares about their shell history, right? 

Or, alternately, one could exit the shell by some means other than sending
it a fatal signal and taking your chances.

I'll file an issue in the Midnight
> Commander bug tracker to use a shell function instead. It might be worth
> documenting the behaviour, though, as it is quite suprising -- shell functions
> don't need to turn off saving to history, so why should `source'?

Because they are parsed and executed separately. Functions are parsed at
definition time and executed when invoked; source scripts are parsed and
executed on the fly a command at a time.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: History not saved when closing terminal while bash is sourcing a script Chet Ramey <chet.ramey@case.edu> - 2019-08-08 08:35 -0400

csiph-web