Hi Dmitry

On Mon, 11 Aug 2025 at 22:17, Шушуев Дмитрий <dima...@live.ru> wrote (in
the attachment):

> Description:
>         Using history builtin with -ps options give unexpected results
>         For example after executing:
>         dnf -q repoquery --list bash-doc | fold -w $(($COLUMNS/3-1)) | pr
> -3tw $COLUMNS
>         if we enter:
>         history -p !!
>         history 10
>         we got:
>         1338  dnf -q repoquery --list bash-doc | fold -w $(($COLUMNS/3-1))
> | pr -3tw $COLUMNS
>         1339  history -p dnf -q repoquery --list bash-doc | fold -w
> $(($COLUMNS/3-1)) | pr -3tw $COLUMNS
>         1340  history 10
>         As you see the 'history -p ...' command got in history though it
> doesn't
>         This only occur this command 'dnf -q repoquery ...'


The issue is that 'history -p' *retroactively* removes itself from the
in-memory history, which normally does what you expect.
However when it's in a subshell it cannot remove itself from the parent
shell's in-memory history.

Consider:

echo Start
> history -p A B C        # (simple command)
> history 1               # outputs « echo Start »
> ( history -p A B C )    # (explicit subshell)
> history 1               # outputs « ( history -p A B C ) »
> history -p A B C | cat  # (implicit subshell within a pipeline)
> history 1               # outputs « history -p A B C | cat »


This is in the same broad class of problem as aliases and « shopt -s
extglob »; they affect early stages of parsing (retroactively, in the case
of history -p) but not until they themselves are *executed*, by which time
it may be too late (or in the wrong context) to have the desired effect.

-Martin

Reply via email to