> On 2018 Jan 21 , at 7:13 a, Ralph Corderoy <ra...@inputplus.co.uk> wrote:
> 
> Hi,
> 
> Please keep me CC'd.
> 
> bash package 4.4.012-2 on Arch Linux,
> `version 4.4.12(1)-release (x86_64-unknown-linux-gnu)'.
> 
> I'm trying to enable history expansion in a non-interactive bash with
> `set -H'.
> 
>    $ printf '%s\n' ': foo' 'echo !!' 'set -H' ': bar' 'echo !!' |
>> bash 
>    !!
>    !!
>    $
> 
> I'd expect the second `!!' to be `: bar'.
> What am I misunderstanding?

You enabled history *expansion*, but not the history mechanism itself, so there 
is nothing for !! to expand to. You need `set -o history` as well.

    $ printf '%s\n' ': foo' 'echo !!' 'set -H -o history' ': bar' 'echo !!' | 
bash
    !!
    echo : bar
    : bar

The second line, 'echo : bar', is the result of the expansion itself, prior to 
the resulting command actually being executed.
    

Reply via email to