history, sourced script problem

May 07, 2023 Last reply: 3 years ago 6 Replies

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



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

Regards, Rudy Wieser

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.

Might be worth asking in comp.unix.shell ?

Nev,

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

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

Jim,

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

comp.os.linux.misc will have the answer

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required