On Wed, Apr 4, 2018 at 5:13 PM, Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> wrote: >> This is the example which is not affected by echo differences: >> >> cat <<EOF >> -\"-\'-\`-\--\z-\*-\?- >> `echo '-\"-\x-\`-\--\z-\*-\?-'` >> $(echo '-\"-\x-\`-\--\z-\*-\?-') >> EOF >> >> # bash z >> -\"-\'-`-\--\z-\*-\?- >> -\"-\x-`-\--\z-\*-\?- >> -\"-\x-\`-\--\z-\*-\?- >> # dash z >> -\"-\'-`-\--\z-\*-\?- >> -"-\x-`-\--\z-\*-\?- >> -\"-\x-\`-\--\z-\*-\?- >> >> IOW: if `cmd` outputs \" in here document, it is converted to " >> whereas bare \" in here document is passed verbatim as \", and >> $(cmd) in here document also does not show this. >> >> Aha... I think `` in heredocs removes \ in commands before >> running them. Thus, `echo '\"'` would run: echo '"' >> >> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_03 >> "Within the backquoted style of command substitution, <backslash> >> shall retain its >> literal meaning, except when followed by: '$', '`', or <backslash>" >> >> I think it should retain \" as \". > > It wasn't the backquote that removed the backslash but the here- > document. This is expected behaviour as here-documents behave > like double quotes so the backslash is indeed special when it > precedes a double quote. This does not match what happens with this simple heredoc: cat <<EOF \" EOF # dash zz \" -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html