bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: history -s from inside function replaces last command rather than ad


From: Greg Wooledge
Subject: Re: history -s from inside function replaces last command rather than adding to it
Date: Mon, 16 Dec 2024 22:13:43 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

On Mon, Dec 16, 2024 at 21:46:21 -0500, Chet Ramey wrote:
> On 12/16/24 9:36 PM, Dale R. Worley wrote:
> > Chet Ramey <chet.ramey@case.edu> writes:
> > > Yes:
> > > 
> > >           -s     Store the args in the history list  as  a  single  entry.
> > >                  The  last  command  in the history list is removed before
> > >                  adding the args.
> > > 
> > > That last command is usually `history -s args'.
> > 
> > What is the point of "history -s args", then?  What is it useful for?
> 
> To add arbitrary data to the history list, for whatever reason a user
> likes. I think the documentation is fairly clear on that.

I think Dale's misunderstanding what Chet's saying.

What Chet's saying, as I understand it, is:

 * Sometimes you want to add "my command" to your history list without
   actually running it.

 * To do that, you run "history -s my command" from your interactive
   shell.

 * A naive implementation would add "my command" and "history -s my command"
   both to your history list.

 * That's probably not what you want, so instead of adding both commands,
   bash only adds the "my command" part, and drops the command that you
   actually typed.

 * The OP of this thread ran into a weird corner case, because they
   didn't actually type "history -s my command" at a shell prompt.  Instead,
   they wrote a function, "foo", and had the function issue the history
   command.

 * When the OP types "foo", bash's implementation adds "my command" to
   the history list, and discards the command that was actually typed,
   which was "foo".



reply via email to

[Prev in Thread] Current Thread [Next in Thread]