help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Question about escaping in backquote string in double quoted


From: KHMan
Subject: [Help-bash] Question about escaping in backquote string in double quoted strings
Date: Fri, 3 May 2019 01:05:47 +0800
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2

Hi all,

I have a question about escaping of the double quote char in a backquote command string nested inside a double quoted string. I have been trying out an example from the Morbig paper[1] and looking at the bash ref man but couldn't figure things out.

Here is a slightly adjusted example from page 4, Example 2.5. Output is at right after the comment #.

echo "[` echo \" \\" \" `]"             # [ " ]      (A)
echo ` echo \" \\" \" `                 # " " "      (B)

In section 3.5.4 Command Substitution, no mention about escaping double quotes is made. I understand (B) but not (A). Who processed the \" into " in (A), because when I tried the $(command) form, no escape processing was done whether the command string is on its own or nested inside a double quoted string (C)-(F):

echo "[$(echo \" )]"                    # ["]        (C)
echo "[$(echo \\"" )]"                  # [\]        (D)
echo $(echo \" )                        # "          (E)
echo $(echo \\"" )                      # \          (F)

It doesn't look like the general escape mechanism either, when I tried \1, the nested and non-nested case looks the same (G)-(H):

echo "[` echo \1 \\1 \1 `]"             # [1 1 1]    (G)
echo ` echo \1 \\1 \1 `                 # 1 1 1      (H)

So my question is, what did bash do in (A), which seems to affect the specific case of the double quote char only?

NOTE: While I used the online bash ref man (Edition 5.0, last updated 7 December 2018), I only managed to run the above snippets on the following with identical results:
  Cygwin / x86_64 - bash 4.4.12(3)
  Linux Mint 19 Live CD / x86_64 - bash 4.4.19(1)


[1] RĂ©gis-Gianas et al, Morbig: A Static Parser for POSIX Shell.

Thanks,
--
Cheers,
Kein-Hong Man (esq.)
Selangor, Malaysia




reply via email to

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