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.
pgpwJscg7UAzW.pgp
Description: PGP signature