Re[2]: history -s from inside function replaces last command rather than adding to it
The second part was just recently added to the doc. Why wasn’t it there before? -- Original Message -- From "Chet Ramey" To "Dale R. Worley" ; bugb...@89vx.net; bug-bash@gnu.org Cc chet.ra...@case.edu Date 12/16/2024 4:46:21 PM Subject Re: history -s from inside function replaces last command rather than adding to it On 12/16/24 9:36 PM, Dale R. Worley wrote: Chet Ramey 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. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
Re[2]: history -s from inside function replaces last command rather than adding to it
I assumed it must be from a more recent bash than I have since mine doesn’t have it: $ help history -pperform history expansion on each ARG and display the result without storing it in the history list -sappend the ARGs to the history list as a single entry If FILENAME is given, it is used as the history file. Otherwise, -- Original Message -- From "Chet Ramey" To "Bug Maybefound" ; bug-bash@gnu.org Cc chet.ra...@case.edu Date 12/17/2024 4:11:29 AM Subject Re: history -s from inside function replaces last command rather than adding to it On 12/17/24 2:01 AM, Bug Maybefound wrote: The second part was just recently added to the doc. Why wasn’t it there before? What does `recent' mean to you? The sentence about removing the last command in the history list has been in the man page since bash-2.0, in 1996, when `history'acquired the `-s' option. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
history -s from inside function replaces last command rather than adding to it
Configuration Information [Automatically generated, do not change]: Machine: aarch64 OS: darwin21.6.0 Compiler: clang Compilation CFLAGS: -DSSH_SOURCE_BASHRC -DDEFAULT_LOADABLE_BUILTINS_PATH='/opt/homebrew/Cellar/bash/5.2.37/lib/b$ uname output: Darwin mini.home 21.6.0 Darwin Kernel Version 21.6.0: Fri Sep 15 16:17:13 PDT 2023; root:xnu-8020.$ Machine Type: aarch64-apple-darwin21.6.0 Bash Version: 5.2 Patch Level: 37 Release Status: release Description: If I make a function that does history -s whatever, that seems to be put in the history instead of the function call rather than along with it. Repeat-By: foo() { echo foo; history -s bar; } Then type foo then up arrow a couple times. I would expect bar then foo. I have to do this to have both in the history: foo() { echo foo; history -s foo "$@"; history -s bar; } Is this working as intended? Thanks!