Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Irrationality is the square root of all evil" -- Douglas Hofstadter


devel / comp.unix.shell / history, sourced script problem.

SubjectAuthor
* history, sourced script problem.R.Wieser
+* Re: history, sourced script problem.Benjamin Esham
|+* Re: history, sourced script problem.Ben Bacarisse
||`- Re: history, sourced script problem.R.Wieser
|`- Re: history, sourced script problem.R.Wieser
+* Re: history, sourced script problem.marrgol
|`- Re: history, sourced script problem.R.Wieser
`* Re: history, sourced script problem.Benjamin Esham
 `* Re: history, sourced script problem.R.Wieser
  +* Re: history, sourced script problem.R.Wieser
  |`* Re: history, sourced script problem.Ben Bacarisse
  | `- Re: history, sourced script problem.R.Wieser
  `* Re: history, sourced script problem.Benjamin Esham
   `- Re: history, sourced script problem.R.Wieser

1
history, sourced script problem.

<u4fn6t$25t0s$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6291&group=comp.unix.shell#6291

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: addr...@is.invalid (R.Wieser)
Newsgroups: comp.unix.shell
Subject: history, sourced script problem.
Date: Mon, 22 May 2023 14:27:33 +0200
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <u4fn6t$25t0s$2@dont-email.me>
Injection-Date: Mon, 22 May 2023 12:29:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a4ed3124fb0e85bd4a1467b1128a09b1";
logging-data="2290716"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DuBVVAwmEiZUsUKX+6EA1qUrRlpKGUMKHAqSV3fmHog=="
Cancel-Lock: sha1:aIO8t3F59znmQLUdU/AJeGOvgx4=
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MSMail-Priority: Normal
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
 by: R.Wieser - Mon, 22 May 2023 12:27 UTC

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

Re: history, sourced script problem.

<rv2f8v.0xhf62@bdesham.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6292&group=comp.unix.shell#6292

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: use...@esham.io (Benjamin Esham)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Mon, 22 May 2023 11:05:51 -0400
Organization: United Federation of Planets
Lines: 17
Message-ID: <rv2f8v.0xhf62@bdesham.net>
References: <u4fn6t$25t0s$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="7bc83c8d95c4b3455e20ee3c7d208de5";
logging-data="2318821"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GqYkuCMYFYBKW46d+U23gYqu50r6AzPMltv0HOe/CxA=="
User-Agent: Gnus/5.13 (macOS)
Cancel-Lock: sha1:rb2shkx0+Nlosr9bJlGrJm55m5o=
sha1:Ej5YTK95r2fvwXJWsQoKJ0kYBwU=
 by: Benjamin Esham - Mon, 22 May 2023 15:05 UTC

R.Wieser wrote:

> Hello all,
>
> I've got a problem with running the "history" command in a sourced
> (preloaded) function:
>
> [snip]

Hi Rudy,

I think we'll need to know which shell you're using, and which version, in
order to give you a good answer.

If you're using Bash--what is $HISTCONTROL set to?

Benjamin

Re: history, sourced script problem.

<87zg5wbc3u.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6293&group=comp.unix.shell#6293

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Mon, 22 May 2023 16:49:09 +0100
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <87zg5wbc3u.fsf@bsb.me.uk>
References: <u4fn6t$25t0s$2@dont-email.me> <rv2f8v.0xhf62@bdesham.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="42b399766ab4854c8d93864eec0e32da";
logging-data="2326762"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Fu7e2cHqYr4O0GDPVgErVgE3wcRpMqQY="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:faNIwfhCMEyYnjcmTgEEJ1iBOjc=
sha1:VOY5wQ0TlvUMUSYDP3rUhUHLteI=
X-BSB-Auth: 1.e3f7408223f3ef57dd88.20230522164909BST.87zg5wbc3u.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 22 May 2023 15:49 UTC

Benjamin Esham <usenet@esham.io> writes:

> R.Wieser wrote:
>
>> Hello all,
>>
>> I've got a problem with running the "history" command in a sourced
>> (preloaded) function:
>>
>> [snip]
>
> Hi Rudy,
>
> I think we'll need to know which shell you're using, and which version, in
> order to give you a good answer.
>
> If you're using Bash--what is $HISTCONTROL set to?

To more things along...

$ bash -norc -noprofile
bash-5.2$ cat x
histtest() {
history -c
history -s "foobar"
} histtest
bash-5.2$ . ./x
bash-5.2$ history
1 foobar
2 history
bash-5.2$ histtest
bash-5.2$ history
1 history
bash-5.2$ bash --version
GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
bash-5.2$ echo $HISTCONTROL

bash-5.2$

--
Ben.

Re: history, sourced script problem.

<u4g9ag$27mqv$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6294&group=comp.unix.shell#6294

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: addr...@is.invalid (R.Wieser)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Mon, 22 May 2023 19:31:46 +0200
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <u4g9ag$27mqv$1@dont-email.me>
References: <u4fn6t$25t0s$2@dont-email.me> <rv2f8v.0xhf62@bdesham.net> <87zg5wbc3u.fsf@bsb.me.uk>
Injection-Date: Mon, 22 May 2023 17:38:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a4ed3124fb0e85bd4a1467b1128a09b1";
logging-data="2349919"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+iAsNJ6k0D6OpuMHlsnLOnA2sCluZ0sWz1lqTCGUZLHA=="
Cancel-Lock: sha1:LZD7x8GUXO8asz5gh7yNegKxeOc=
X-RFC2646: Format=Flowed; Original
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
 by: R.Wieser - Mon, 22 May 2023 17:31 UTC

Ben

> To more things along...
....
> bash-5.2$ . ./x
> bash-5.2$ history
> 1 foobar
> 2 history
> bash-5.2$ histtest
> bash-5.2$ history
> 1 history

Yes, thats what I'm getting too. And as far as I can tell, should not get.

Than again, my knowledge of Linux and bash is rather minimal. Perhaps there
is a good reason why it behaves like that, and there is a setting to gouvern
it ?

Regards,
Rudy Wieser

Re: history, sourced script problem.

<u4g9ah$27mqv$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6295&group=comp.unix.shell#6295

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: addr...@is.invalid (R.Wieser)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Mon, 22 May 2023 19:38:15 +0200
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <u4g9ah$27mqv$2@dont-email.me>
References: <u4fn6t$25t0s$2@dont-email.me> <rv2f8v.0xhf62@bdesham.net>
Injection-Date: Mon, 22 May 2023 17:38:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a4ed3124fb0e85bd4a1467b1128a09b1";
logging-data="2349919"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196jaRA/lUE5IH2Vsm7GYOzVz+jQr6zxEvu3yM5DBn3bw=="
Cancel-Lock: sha1:g5gQYa9UVm/NZVLnekiTjU3JD8M=
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-Priority: 3
X-RFC2646: Format=Flowed; Original
 by: R.Wieser - Mon, 22 May 2023 17:38 UTC

Benjamin,

> If you're using Bash-

Indeed I am.

> -what is $HISTCONTROL set to?

Its currently set to

"ignorespace:erasedups"

, Which is a setting I applied myself.

By the way, if its relevant (thanks ben),

$ bash --version

shows

"GNU bash, version 5.1.4(1)"

Regards,
Rudy Wieser

Re: history, sourced script problem.

<u4gt1n$29qp9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6296&group=comp.unix.shell#6296

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: marr...@address.invalid (marrgol)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Tue, 23 May 2023 01:15:02 +0200
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <u4gt1n$29qp9$1@dont-email.me>
References: <u4fn6t$25t0s$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 22 May 2023 23:15:03 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0931867b0f502ae71dc5bbd3a6a0e7e3";
logging-data="2419497"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Fjo12R7ggqga2s+PDD2rl"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:9cyqCNnIwUOZckkc0rVjzZBCDP4=
Content-Language: en-US
In-Reply-To: <u4fn6t$25t0s$2@dont-email.me>
 by: marrgol - Mon, 22 May 2023 23:15 UTC

On 22/05/2023 at 14.27, R.Wieser wrote:
> 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.

I'm just guessing but I think it might be related to _when_ the clearing
is actually done and that history list stores command _lines_ but one
line can contain multiple commands. E.g.:

$ history -c
$ history -s foo
$ history
1 foo
2 history

is what you'd expect, but

$ echo zzz ; history -c ; history -s foo
zzz
$ history
1 history

probably is not, unless clearing history is by design performed after
the whole line is interpreted/executed.

I don't know if it can be fixed (or if there's anything to be fixed)
but since sourcing works as expected, why not just utilize it?

$ cat /path/file
history -c
history -s foobar
histtest () { . /path/file ; }
$ . /path/file
$ history
1 foobar
2 history
$ histtest
$ history
1 foobar
2 history
$

HTH

--
mrg

Re: history, sourced script problem.

<u4hov3$2frp9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6297&group=comp.unix.shell#6297

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: addr...@is.invalid (R.Wieser)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Tue, 23 May 2023 09:11:16 +0200
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <u4hov3$2frp9$1@dont-email.me>
References: <u4fn6t$25t0s$2@dont-email.me> <u4gt1n$29qp9$1@dont-email.me>
Injection-Date: Tue, 23 May 2023 07:11:31 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="34a6b1838aa21c6f71cf2e8b476e6e66";
logging-data="2617129"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2/f2Nmcn2YbYVeCMHkQIs6fHw2s6vYckPmB65NiN80Q=="
Cancel-Lock: sha1:77xXpiMhA4dupirGEwr6oNMFdWc=
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Priority: 3
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-MSMail-Priority: Normal
 by: R.Wieser - Tue, 23 May 2023 07:11 UTC

marrgol,

> I'm just guessing but I think it might be related to _when_ the clearing
> is actually done

Yes, that was what I was thinking too. But thats the strange thing : why
does, in this case, clearing behave differently than adding ?

> $ echo zzz ; history -c ; history -s foo
> zzz
> $ history
> 1 history
>
> probably is not,

No, its not. Than again, I'm not sure if the above (sub) commands are
executed in sequence or if its done in parallel - in which case I could
imagine a race condition.

> unless clearing history is by design performed after the whole line is
> interpreted/executed.

The same went thru my mind too. But in that case, why ? Such out-of-order
behaviour causes the very, unexpected, problem I bumped into.

> I don't know if it can be fixed (or if there's anything to be fixed)

Currently I will settle for knowing /why/ it happens - so that I won't run
into it again when trying to use some other command/program instead of
"history".

> but since sourcing works as expected, why not just utilize it?
[snip]

I just tried it, and it does give the expected outcome. Thanks for that
(generic usable!) solution.

Its odd though : when running the script thru the "histtest" invocation the
script is /already/ running in the main shells environment, and sourcing it
there should not even work/make any difference (and I therefore didn't try
it). But here I am, looking at it and seeing that it /does/ make a
difference ...

.... almost as if "sourcing" a script there makes it run in some special
environment/subshell.

Thanks for the response and solution. Its has been irking me for weeks now.
:-\

Regards,
Rudy Wieser

Re: history, sourced script problem.

<rv4gue.zhhc5f@bdesham.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6298&group=comp.unix.shell#6298

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: use...@esham.io (Benjamin Esham)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Tue, 23 May 2023 14:22:30 -0400
Organization: United Federation of Planets
Lines: 61
Message-ID: <rv4gue.zhhc5f@bdesham.net>
References: <u4fn6t$25t0s$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="dba4a83f83342df0472bbff202137168";
logging-data="2801420"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18i/Wg1pvw8NkcHpg0Ev2RgY3BktVeabI4RfTqwAqNArQ=="
User-Agent: Gnus/5.13 (macOS)
Cancel-Lock: sha1:A6mi35JnT8GgvuPo1x8Udp6sGnE=
sha1:wDfBMBw1EG1NSHZHpFW9V+MMuyA=
 by: Benjamin Esham - Tue, 23 May 2023 18:22 UTC

R.Wieser wrote:

> 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.

The Bash manual seems misleading about how the "history" command works. It
claims that the -c option "may be combined with the other options to replace
the history list completely," but if you try the obvious thing,

history -c -s foobar

the history is simply cleared and no "foobar" entry is present afterward.

I did find a solution that seems to work with Bash 5.2.15(1)-release:

histtest() {
history -s foobar
history -d 1--2
}

This inverts the steps in your version of histtest: first we add the
"foobar" entry, and then we remove all of the entries except for the most
recent one. "1--2" may look like a typo, but it's a range of two history
entries: from entry 1 (the earliest entry in the list) to entry -2 (the
second to last entry in the list). The -d option accepts a hyphen-separated
range, and it also accepts negative numbers for counting back from the end
of the list, so in a case like this you end up with two consecutive hyphens.

I noticed that if the function only runs "history -s foobar", and does not
delete any history entries, the *invocation* of the function is nevertheless
excluded from the history listing. In other words, if you run the three
commands

histtest2() { history -s foobar2; }
histtest2
history

then the history listing will include "foobar2" but it will not show that
you ran "histtest2"! I'm not a Bash user, but I am inclined to agree with
you that Bash's handling of history within functions seems inconsistent with
how it works otherwise.

Hope this helps,

Benjamin

Re: history, sourced script problem.

<u4kduv$2tgh5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6299&group=comp.unix.shell#6299

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: addr...@is.invalid (R.Wieser)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Wed, 24 May 2023 09:21:51 +0200
Organization: A noiseless patient Spider
Lines: 83
Message-ID: <u4kduv$2tgh5$1@dont-email.me>
References: <u4fn6t$25t0s$2@dont-email.me> <rv4gue.zhhc5f@bdesham.net>
Injection-Date: Wed, 24 May 2023 07:22:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="46812b21c1355e7261e2c4103e88ac8e";
logging-data="3064357"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18EZCCU5fdZupQH0On8NCEcvKakWt7+dZfA0sd55Y3viQ=="
Cancel-Lock: sha1:IkwFSkDj9GCwOZBM8raE4FRwJUI=
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-MSMail-Priority: Normal
 by: R.Wieser - Wed, 24 May 2023 07:21 UTC

Benjamin,

> The Bash manual seems misleading about how the "history" command works.
> It claims that the -c option "may be combined with the other options to
> replace the history list completely," but if you try the obvious thing,
>
> history -c -s foobar
>
> the history is simply cleared and no "foobar" entry is present afterward.

There is a (good) possibility that its not the history command itself thats
to blame, but the underlaying bash (or OS).

> I did find a solution that seems to work with Bash 5.2.15(1)-release:
>
> histtest() {
> history -s foobar
> history -d 1--2
> }

I was also thinking of that (did first try to replace the "-c" with a
full-range "-d" to see if it would make a difference), but didn't really
want to go for "circumvent the problem" hacks. Besides having to keep track
of how many "history -s" additions I would be doing to be able to remove the
rest.

In that regard I already I already found a "solution" to the problem by
echo-ing the "history -s" parts into a file, and than load that file after I
cleared the history. It works well enough, but I don't like it.

<following a brainfart and doing some checking>

Funny : that "history -d 1--2" causes a quite unexpected behaviour :

> - - - - - - - - - -
> histtest() {
> history -d 1--2
> history -s "foobar"
> history -s "barfoo"
> history -s "more stuff"
> }
> histtest
> - - - - - - - - - -

Sourcing this script causes the history to end up with four lines, the
oldest one being the command sourcing the script.

However, if I than afterwards execute "histstest" I get just the
"history -s" lines. <whut? why don't they disappear now ?>

If I would be a fan of hacks that won't break down when the underlaying
problem is fixed than I would probably use this one. :-)

Hmmm... Somehow I get the feeling that some lazy memory allocation (new
storage for the history) is involved.

> I noticed that if the function only runs "history -s foobar", and does
> not delete any history entries, the *invocation* of the function is
> nevertheless excluded from the history listing. In other words, if you
> run the three commands
>
> histtest2() { history -s foobar2; }
> histtest2
> history
>
> then the history listing will include "foobar2" but it will not show
> that you ran "histtest2"!

IIRC, that is defined behaviour : only commands started from the commandline
(typed by the user!) are remembered in the history.

And I don't think you really want to have it remember everything - just take
a peek at the output of "declare -F" (or "declare -f" if you want to see the
contentst too) to see how may scripts bash has predefined. Imagine yourself
having to wade thru a sh*tload of bash commands that you can't remember
having ever typed (because you didn't) ...

Regards,
Rudy Wieser

Re: history, sourced script problem.

<u4l2lj$2vlrb$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6300&group=comp.unix.shell#6300

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: addr...@is.invalid (R.Wieser)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Wed, 24 May 2023 15:15:19 +0200
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <u4l2lj$2vlrb$1@dont-email.me>
References: <u4fn6t$25t0s$2@dont-email.me> <rv4gue.zhhc5f@bdesham.net> <u4kduv$2tgh5$1@dont-email.me>
Injection-Date: Wed, 24 May 2023 13:15:31 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="46812b21c1355e7261e2c4103e88ac8e";
logging-data="3135339"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bgN7ThukuXKr7N8aKto4FAD6BwBSXkxvsstrlZAcZLA=="
Cancel-Lock: sha1:BTmo1QGpb9R/LEDMEQNKvLWifYc=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-MSMail-Priority: Normal
X-RFC2646: Format=Flowed; Response
X-Priority: 3
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
 by: R.Wieser - Wed, 24 May 2023 13:15 UTC

Update :

I just tried the below and it works the same way, showing just the three
"-s" lines after the "-c", either by sourcing it or (afterwards) just
executing the function :

- - - - - - - - - -
histtest() {
history -s dummy
history -c
history -s foobar
history -s barfoo
history -s more stuff
} histtest
- - - - - - - - - -

FWI : I started with "history 1--2", but that throws an error when the
history is empty - otherwise an "out of range" error is thrown and nothing
is added.

I'm back to being baffled, both in regard to the result as well as what
might be causing it.

Regards,
Rudy Wieser

Re: history, sourced script problem.

<rv657z.8q6k33@bdesham.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6301&group=comp.unix.shell#6301

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: use...@esham.io (Benjamin Esham)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Wed, 24 May 2023 11:33:44 -0400
Organization: United Federation of Planets
Lines: 67
Message-ID: <rv657z.8q6k33@bdesham.net>
References: <u4fn6t$25t0s$2@dont-email.me> <rv4gue.zhhc5f@bdesham.net>
<u4kduv$2tgh5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="5ce145c58c0377ce706b918319303119";
logging-data="3166492"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Y8V2YEQ4Hsh45RU597jVi9vo6wV+9S1ewy3tnLW9guA=="
User-Agent: Gnus/5.13 (macOS)
Cancel-Lock: sha1:yItCvRPfiH7+TyJx5zI/QHp7H8g=
sha1:8EqaPTHcpBiGZWVr3e1llXeVoZ0=
 by: Benjamin Esham - Wed, 24 May 2023 15:33 UTC

R.Wieser wrote:

> Benjamin,
>
>> The Bash manual seems misleading about how the "history" command works.
>> It claims that the -c option "may be combined with the other options to
>> replace the history list completely," but if you try the obvious thing,
>>
>> history -c -s foobar
>>
>> the history is simply cleared and no "foobar" entry is present afterward.
>
> There is a (good) possibility that its not the history command itself
> thats to blame, but the underlaying bash (or OS).

The history command is part of Bash, so I'm not sure that that distinction
is meaningful.

>> I did find a solution that seems to work with Bash 5.2.15(1)-release:
>>
>> histtest() {
>> history -s foobar
>> history -d 1--2
>> }
>
> I was also thinking of that (did first try to replace the "-c" with a
> full-range "-d" to see if it would make a difference), but didn't really
> want to go for "circumvent the problem" hacks. Besides having to keep
> track of how many "history -s" additions I would be doing to be able to
> remove the rest.

I don't know how complicated your real version of histtest is, but you might
consider creating an array of items that should be added to the history.
Then you can have Bash itself calculate how many history entries need to be
removed. You could even check the current size of the history so that you
don't try to remove any entries when there aren't any entries to remove.

> In that regard I already I already found a "solution" to the problem by
> echo-ing the "history -s" parts into a file, and than load that file after
> I cleared the history. It works well enough, but I don't like it.

I think you could make an alias that writes your commands to a (temporary)
history file and then starts a separate instance of Bash that uses that file
for its history. I'm not sure I'd consider that a hack or anything; it seems
like your use case is pretty different from the typical use of Bash's
history mechanism, so it shouldn't be surprising that not everything you
need is already built in.

>> I noticed that if the function only runs "history -s foobar", and does
>> not delete any history entries, the *invocation* of the function is
>> nevertheless excluded from the history listing. In other words, if you
>> run the three commands
>>
>> histtest2() { history -s foobar2; }
>> histtest2
>> history
>>
>> then the history listing will include "foobar2" but it will not show
>> that you ran "histtest2"!
>
> IIRC, that is defined behaviour : only commands started from the
> commandline (typed by the user!) are remembered in the history.

My point is that the user *did* type in "histtest2" and yet that command
does not appear in the history.

Benjamin

Re: history, sourced script problem.

<87r0r5afwt.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6302&group=comp.unix.shell#6302

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Wed, 24 May 2023 16:49:06 +0100
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <87r0r5afwt.fsf@bsb.me.uk>
References: <u4fn6t$25t0s$2@dont-email.me> <rv4gue.zhhc5f@bdesham.net>
<u4kduv$2tgh5$1@dont-email.me> <u4l2lj$2vlrb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="b9cc908751751445f822c2f0b2420f5c";
logging-data="3167631"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18eyLVCgYXFftkGZ8UPYF34sr8DtoaMB9I="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:0zp/oExgezYmTwQtFyfuptj0I6w=
sha1:lCMikCbPRnEIPEcyCCFLr91aviI=
X-BSB-Auth: 1.8c9249b8851733e5973e.20230524164907BST.87r0r5afwt.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 24 May 2023 15:49 UTC

"R.Wieser" <address@is.invalid> writes:

> Update :
>
> I just tried the below and it works the same way, showing just the three
> "-s" lines after the "-c", either by sourcing it or (afterwards) just
> executing the function :
>
> - - - - - - - - - -
> histtest() {
> history -s dummy
> history -c
> history -s foobar
> history -s barfoo
> history -s more stuff
> }
> histtest
> - - - - - - - - - -
>
> FWI : I started with "history 1--2", but that throws an error when the
> history is empty - otherwise an "out of range" error is thrown and nothing
> is added.
>
> I'm back to being baffled, both in regard to the result as well as what
> might be causing it.

This is very odd. Just having one -s before the -c makes things work as
expected (for me):

bash-5.2$ cat x2
histtest() {
history -s dummy
history -c
history -s foobar
} histtest

but commenting out that "history -s dummy" line and we are back to the
original odd behaviour. Replacing that line with a plain "history"
command does not help either.

--
Ben.

Re: history, sourced script problem.

<u4lelg$3124b$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6303&group=comp.unix.shell#6303

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: addr...@is.invalid (R.Wieser)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Wed, 24 May 2023 18:32:05 +0200
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <u4lelg$3124b$1@dont-email.me>
References: <u4fn6t$25t0s$2@dont-email.me> <rv4gue.zhhc5f@bdesham.net><u4kduv$2tgh5$1@dont-email.me> <rv657z.8q6k33@bdesham.net>
Injection-Date: Wed, 24 May 2023 16:40:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="46812b21c1355e7261e2c4103e88ac8e";
logging-data="3180683"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189yOm+pWhAvVuKNrcCAdxtbvTh6TZii/eska4uaXPGWg=="
Cancel-Lock: sha1:rJZ+DDxGLqlc/zvY6wAJbZwnseI=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MSMail-Priority: Normal
X-Priority: 3
 by: R.Wieser - Wed, 24 May 2023 16:32 UTC

Benjamin,

> I don't know how complicated your real version of histtest is,

It currently(!) isn't.

> but you might consider creating an array of items that should be
> added to the history.

Thats one of the possibilities, yes. Incrementing a counter every time that
"history -s" is executed would be another.

> My point is that the user *did* type in "histtest2" and yet that
> command does not appear in the history.

My apologies, I was assuming that those three lines where inside a script
too.

It might have something to do with "histtest2" being a preloaded function.

Regards,
Rudy Wieser

Re: history, sourced script problem.

<u4lelg$3124b$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6304&group=comp.unix.shell#6304

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: addr...@is.invalid (R.Wieser)
Newsgroups: comp.unix.shell
Subject: Re: history, sourced script problem.
Date: Wed, 24 May 2023 18:40:02 +0200
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <u4lelg$3124b$2@dont-email.me>
References: <u4fn6t$25t0s$2@dont-email.me> <rv4gue.zhhc5f@bdesham.net><u4kduv$2tgh5$1@dont-email.me> <u4l2lj$2vlrb$1@dont-email.me> <87r0r5afwt.fsf@bsb.me.uk>
Injection-Date: Wed, 24 May 2023 16:40:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="46812b21c1355e7261e2c4103e88ac8e";
logging-data="3180683"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vjbdCmj4T8p9OFKRN3AX5y/RRVkQnYi+/80mMQ+yyXQ=="
Cancel-Lock: sha1:uPbj/VMRU/3ITg2CfsHdHdBOKoc=
X-MSMail-Priority: Normal
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
 by: R.Wieser - Wed, 24 May 2023 16:40 UTC

Ben,

> This is very odd.

Indeed.

> Just having one -s before the -c makes things work as expected (for
> me):

One or more. Though having more that one is rather useless ofcourse.

> but commenting out that "history -s dummy" line and we are back to
> the original odd behaviour.

And back to the initial example. :-)

Regards,
Rudy Wieser

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor