Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15182 > unrolled thread
| Started by | astian <astian@e-nautia.com> |
|---|---|
| First post | 2019-07-16 19:03 +0000 |
| Last post | 2019-07-16 19:03 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: backquote peculiarities astian <astian@e-nautia.com> - 2019-07-16 19:03 +0000
| From | astian <astian@e-nautia.com> |
|---|---|
| Date | 2019-07-16 19:03 +0000 |
| Subject | Re: backquote peculiarities |
| Message-ID | <mailman.1526.1563309668.2688.bug-bash@gnu.org> |
Chet Ramey:
> On 7/15/19 6:19 PM, astian wrote:
>
>>> I doubt it makes any difference to the timing, which I think
>>> Chet has already answered, but it is worth pointing out that these
>>> two commands ...
>>>
>>> printf '%s\n' "`printf %s "$i"`"
>>> printf '%s\n' "$(printf %s "$i")"
>>>
>>> which (I believe)) are supposed to be the same thing, using the
>>> different (ancient, and modern) forms of command substitution aren't
>>> actually the same. In the first $i is unquoted, in the second it is
>>> quoted. Here, since its value is just a number and IFS isn't being
>>> fiddled, there is not likely to be any effect, but if you really
>>> want to make those two the same, the first needs to be written as
>>>
>>> printf '%s\n' "`printf %s \"$i\"`"
>>>
>>> Such are the joys of `` command substitutions (just avoid them).
>>>
>>> kre
>>
>> Dear Robert Elz, I'm aware of several of its peculiarities and I typically do
>> avoid them. However, is it true that $i is unquoted in the first case?
>
> POSIX makes it undefined behavior, and different shells do it differently.
> Bash makes the $i quoted within the `` string, as you discovered.
Ah, thanks for the clarification. I wonder if the excerpt below (particularly
the last sentence) would be the relevant wording of POSIX, i.e. that some
shells might interpret the command as the concatenation of a double-quoted
string, the unquoted $i, and another double-quoted string:
"`printf %s "$i"`" => CONCAT("`printf %s ", $i, "`")
Which would then lead to "undefined results".
Cheers.
---
2.2.3 Double-Quotes [0]
Enclosing characters in double-quotes ( "" ) shall preserve the literal value
of all characters within the double-quotes, with the exception of the
characters backquote, <dollar-sign>, and <backslash>, as follows:
[...]
`
The backquote shall retain its special meaning introducing the other
form of command substitution (see Command Substitution). [...] Either of
the following cases produces undefined results:
- A single-quoted or double-quoted string that begins, but does not
end, within the "`...`" sequence
- A "`...`" sequence that begins, but does not end, within the same
double-quoted string
[...]
0: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_03
Back to top | Article view | gnu.bash.bug
csiph-web