[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `eval` pollutes the history when it runs "set -o history"

From: Chet Ramey
Subject: Re: `eval` pollutes the history when it runs "set -o history"
Date: Mon, 10 Jun 2019 09:22:26 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.7.0

On 6/8/19 3:41 PM, address@hidden wrote:

> Bash Version: 5.0
> Patch Level: 7
> Release Status: release
> Description:
>       When `eval` runs "set -o history", subsequent lines in the
>       eval-ed string are recorded in the history.

Yes. History doesn't require an interactive shell to work; you can save
commands in the history list and use the history commands to operate on
them in any shell that runs `set -o history'.

>       This breaks the following coding pattern:
>               saved_options="$(set +o)" # save shell options
>               ... # do some things with custom shell options
>               eval "$saved_options" # restore shell options
>       Indeed, if history is enabled (which is very likely), then the
>       output of "set +o" will include the line "set -o history",
>       followed by lines for enabling or disabling other options, and
>       these following lines pollute the user’s history.
>       What makes me think it is an actual bug is that when the
>       "history" option was already enabled, "set -o history" should
>       have no effect; yet lines before are not recorded, and lines
>       after are recorded.

Bash temporarily stops recording commands in the history when you use
`eval', but if you turn history back on explicitly using `set -o history',
it will honor that.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]