[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".
- history -s from inside function replaces last command rather than adding to it, Bug Maybefound, 2024/12/13
- Re: history -s from inside function replaces last command rather than adding to it, Chet Ramey, 2024/12/14
- Re: history -s from inside function replaces last command rather than adding to it, Dale R. Worley, 2024/12/16
- Re: history -s from inside function replaces last command rather than adding to it, Chet Ramey, 2024/12/16
- Re: history -s from inside function replaces last command rather than adding to it,
Greg Wooledge <=
- Re[2]: history -s from inside function replaces last command rather than adding to it, Bug Maybefound, 2024/12/17
- Re: history -s from inside function replaces last command rather than adding to it, Chet Ramey, 2024/12/17
- Re[2]: history -s from inside function replaces last command rather than adding to it, Bug Maybefound, 2024/12/17
- Re: history -s from inside function replaces last command rather than adding to it, Greg Wooledge, 2024/12/17
- Re: history -s from inside function replaces last command rather than adding to it, Chet Ramey, 2024/12/17
- Re: history -s from inside function replaces last command rather than adding to it, Dale R. Worley, 2024/12/17
- Re: history -s from inside function replaces last command rather than adding to it, Chet Ramey, 2024/12/18
- Re: history -s from inside function replaces last command rather than adding to it, Dale R. Worley, 2024/12/18
- Re: history -s from inside function replaces last command rather than adding to it, Chet Ramey, 2024/12/18
- Re: history -s from inside function replaces last command rather than adding to it, microsuxxor, 2024/12/18