[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Expansion of exclamation mark in single quotes in subcommand
From: |
Chris Down |
Subject: |
Re: Expansion of exclamation mark in single quotes in subcommand |
Date: |
Mon, 21 Apr 2014 23:48:47 +0800 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
Maxdamantus writes:
> It's not just inside a double-quoted block. It's inside a single-quoted block.
No, your ultimate expansion is in a double quoted block. What happens
inside the command substitution does not matter.
> The last two commands in my first email demonstrate that the $
> expansion is aware of that, so it follows the rule of everything
> inside single-quote blocks being literal except for the single quote
> itself. ! doesn't.
No, that's to do with the order of operations. History expansion and
parameter expansion are performed at two totally separate points during
parsing.
> echo "$(echo "$$")" # here, $$ is double-quoted, so should be expanded
> to something (it is)
> echo "$(echo '$$')" # here, $$ is single-quoted, so shouldn't be
> expand to something (it isn't)
This is because the parameter expansion has already been performed, so
you're too late to expand $$.
> echo "$(echo "!!")" # here, !! is double-quoted, so should be expanded
> to something (it is)
> echo "$(echo '!!')" # here, !! is single-quoted, so shouldn't be
> expanded to something (it is—this seems wrong)
!! 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).
> I think my second email shows even more clearly that it's a bug: each
> time you nest a subcommand, the behaviour changes: it alternates
> between expanding an non-expanding
The reason !! can be expanded and $$ can not is purely because of the
order of expansions, which is clearly documented in the manual.
pgp3Z0ZFHTcNB.pgp
Description: PGP signature
Re: Expansion of exclamation mark in single quotes in subcommand, Chet Ramey, 2014/04/21