• history, sourced script problem

    From R.Wieser@3:770/3 to All on Sun May 7 07:42:52 2023
    Hello all,

    I've got a problem with running the "history" command in a sourced
    (preloaded) function:

    - - - - - - - - - -
    histtest() {
    history -c
    history -s "foobar"
    }
    histtest
    - - - - - - - - - -

    When I source this script the history gets cleared and the "foobar" entry is added to it. IOW, it works as expected.

    However, when I than afterwards just type "histtest" on the commandline the history is cleared, but the "foobar" entry isn't added.

    Question: what causes the difference and how do I fix it ?

    Remark: the trouble seems to come from clearing the history. When I remove that line the "foobar" entry is, in both cases, added as expected.

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From R.Wieser@3:770/3 to All on Mon May 22 08:52:16 2023
    Can someone at least test the script and tell me if it works the same (unexpected to me) way for you ?

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From nev young@3:770/3 to R.Wieser on Mon May 22 11:29:42 2023
    On 22/05/2023 07:52, R.Wieser wrote:
    Can someone at least test the script and tell me if it works the same (unexpected to me) way for you ?

    yes.
    not tested on a pi but on x86 machine running mint.

    when I type the commands it does clear the history then adds foobar but
    when run with the command histtest it just clears the history.

    almost looks as if the clear is performed on exit from the function.


    --
    Nev
    It causes me a great deal of regret and remorse
    that so many people are unable to understand what I write.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Jim Jackson@3:770/3 to R.Wieser on Mon May 22 12:06:26 2023
    On 2023-05-22, R.Wieser <address@is.invalid> wrote:

    Can someone at least test the script and tell me if it works the same (unexpected to me) way for you ?


    Might be worth asking in comp.unix.shell ?

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From R.Wieser@3:770/3 to All on Mon May 22 14:25:42 2023
    Nev,

    Can someone at least test the script and tell me if it works the same
    (unexpected to me) way for you ?

    yes.

    not tested on a pi but on x86 machine running mint.

    Even better ! It means (to me) that its common behaviour, not because of
    some RPi specific adjustment.

    almost looks as if the clear is performed on exit from the function.

    Yes, thats pretty-much the same conclusion I came to. On the other hand, I
    do not know anything about the innards of bash, so it /could/ be something
    else altogether .. :-)

    Thanks for the testing.

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From R.Wieser@3:770/3 to All on Mon May 22 14:29:10 2023
    Jim,

    Might be worth asking in comp.unix.shell ?

    Thanks for that. Just copy-pasted the question into that newsgroup. Lets
    see if they know what causes it ...

    I also posted a similar/same question into alt.os.linux, but have not seen
    any response. :-\

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From The Natural Philosopher@3:770/3 to Jim Jackson on Mon May 22 23:35:46 2023
    On 22/05/2023 13:06, Jim Jackson wrote:
    On 2023-05-22, R.Wieser <address@is.invalid> wrote:

    Can someone at least test the script and tell me if it works the same
    (unexpected to me) way for you ?


    Might be worth asking in comp.unix.shell ?


    comp.os.linux.misc will have the answer
    --
    Socialism is the philosophy of failure, the creed of ignorance and the
    gospel of envy.

    Its inherent virtue is the equal sharing of misery.

    Winston Churchill

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)