[Top][All Lists]

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

Re: Expansion of exclamation mark in single quotes in subcommand

From: Maxdamantus
Subject: Re: Expansion of exclamation mark in single quotes in subcommand
Date: Tue, 22 Apr 2014 04:39:24 +1200

On 22 April 2014 04:24, Maxdamantus <address@hidden> wrote:
> Yeah, I can see what you're saying, but it would probably lead to the
> bash-2 behaviour, which didn't observe double quotes.
> Given: echo "$(echo "foo")"
> I can't see how it would be desirable for anything to consider
> '"$(echo "' and '")"' to be quoted and the rest, 'echo ' and 'foo' to
> be unquoted.
> With the bash-2 behaviour, the only quotes history expansion is aware
> of is single quotes, which can't contain another set of single quotes.
> It looks like the current behaviour was added into bash-3 to make
> history expansion more consistent with other expansions, but without
> realising double quotes can be nested in the somewhat separate bash
> language.
> Maybe I should show some practical-looking commands that
> (unexpectedly) runs into the problem:
> $ sed '3,10!d' <messages
> <lines 3–10 of messages shown, user decides to save them into a variable>
> $ m="$(sed '3,10!d' <messages)"
> -bash: !d': event not found
> Ironically, this actually works if the user instead writes: m="$(!!)"
> In the process, it will print out the invalid command just above as if
> that's the one it's executing.
> On 22 April 2014 03:55, Chris Down <address@hidden> wrote:
>> Chris Down writes:
>>> !! is not single-quoted in the ultimate expansion (bash knows nothing
>>> about what happens inside the subshell), which is all that matters. It's
>>> not too late to perform history expansion (which is different than
>>> parameter expansion).
>> To be more clear, the history expansion is performed immediately after
>> the line is read, before word splitting takes place.
>> Perhaps this may be undesirable(?), but I don't think it's unexpected
>> behaviour.

reply via email to

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