* Is outer quoting not needed (docs say "redundant")? @ 2017-12-12 13:41 ` Sebastian Gniazdowski 2017-12-12 15:00 ` Peter Stephenson 0 siblings, 1 reply; 7+ messages in thread From: Sebastian Gniazdowski @ 2017-12-12 13:41 UTC (permalink / raw) To: Zsh Users Hello, manual says: "in "${(@f)"$(foo)"}", there are two sets of quotes, one surrounding the whole expression, the other (redundant) surrounding the $(foo) as before." One user reported that single, outer quoting always worked for him. Word "redundant" quite confirms this, but can we be sure? Nevertheless, I'll add a note to my handbook, will not replace example, because it well showns that quotings don't e.g. cancel each other (on the other hand, inner quoting doesn't have a real role, hm). -- Sebastian Gniazdowski psprint /at/ zdharma.org ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is outer quoting not needed (docs say "redundant")? 2017-12-12 13:41 ` Is outer quoting not needed (docs say "redundant")? Sebastian Gniazdowski @ 2017-12-12 15:00 ` Peter Stephenson 2017-12-13 7:00 ` Sebastian Gniazdowski 0 siblings, 1 reply; 7+ messages in thread From: Peter Stephenson @ 2017-12-12 15:00 UTC (permalink / raw) To: Zsh Users On Tue, 12 Dec 2017 14:41:26 +0100 Sebastian Gniazdowski <psprint@zdharma.org> wrote: > manual says: > "in "${(@f)"$(foo)"}", there are two sets of quotes, one > surrounding the whole expression, the other (redundant) surrounding > the $(foo) as before." > > One user reported that single, outer quoting always worked for > him. Word "redundant" quite confirms this, but can we be sure? The quoting is done at an early stage, by the lexical analyser. Double quotes are handled as a special form of analysis (function dquote_parse()) ensuring that - everything in the quotes is marked as being within the quotes; - in particular, "$" are tokenised differently compared with "$" outside double quotes, so the parameter substitution behaves correctly; - ${ ... } expressions must complete before the end of the quotes --- so double quotes internally are noted as tokens but don't affect the top level parsing. The internal double quotes show up as part of the argument of the parameter substitution because they're not removed until we've analysed the substitution. So if necessary they will flag up the fact that the internal expression is double quoted. But because the parameter substitution in this case is already double quoted, they have no additional effect. There may be a better example to use in the manual: the example here uses the "@" flag for splitting, which is only meaningful if the outer quotes are present. But it does have the use of pointing out that the double quotes are nested --- which might not be obvious, you might naively think the "${" and "}" were in two different double-quoted expressions. pws ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is outer quoting not needed (docs say "redundant")? 2017-12-12 15:00 ` Peter Stephenson @ 2017-12-13 7:00 ` Sebastian Gniazdowski 2017-12-13 11:34 ` Peter Stephenson 0 siblings, 1 reply; 7+ messages in thread From: Sebastian Gniazdowski @ 2017-12-13 7:00 UTC (permalink / raw) To: Peter Stephenson, Zsh Users On 12 Dec 2017 at 16:00:24, Peter Stephenson (p.stephenson@samsung.com) wrote: > the substitution. So if necessary they will flag up the fact that the > internal expression is double quoted. But because the parameter > substitution in this case is already double quoted, they have no > additional effect. > > There may be a better example to use in the manual: the example here > uses the "@" flag for splitting, which is only meaningful if the outer > quotes are present. But it does have the use of pointing out that > the double quotes are nested --- which might not be obvious, you > might naively think the "${" and "}" were in two different > double-quoted expressions. Yes the example shows this and that's why I'd keep it. Going further, I once had serious doubts about such quotings overlapping. Digged out a code: gitout=( "${(@f)"$( "${gitcmd[@]}" )"}" ) Is it the same? Top-level quotes mark ${gitcmd[@]} as quoted, so splitting, etc. is done regardless of bottom quoting, but each quoting is kept separate and they don't interact when they are parsed? -- Sebastian Gniazdowski psprint /at/ zdharma.org ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is outer quoting not needed (docs say "redundant")? 2017-12-13 7:00 ` Sebastian Gniazdowski @ 2017-12-13 11:34 ` Peter Stephenson 2018-01-13 16:50 ` Sebastian Gniazdowski 0 siblings, 1 reply; 7+ messages in thread From: Peter Stephenson @ 2017-12-13 11:34 UTC (permalink / raw) To: Zsh Users On Wed, 13 Dec 2017 08:00:51 +0100 Sebastian Gniazdowski <psprint@zdharma.org> wrote: > Going further, I once had serious doubts about such quotings > overlapping. Digged out a code: > > gitout=( "${(@f)"$( "${gitcmd[@]}" )"}" ) > > Is it the same? It should be, because the count of braces doesn't go to zero between the first "${" and the last "}" (see the rules I summarised last time). So only the final double quote causes quoting to end. pws ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is outer quoting not needed (docs say "redundant")? 2017-12-13 11:34 ` Peter Stephenson @ 2018-01-13 16:50 ` Sebastian Gniazdowski 2018-01-13 17:36 ` Bart Schaefer [not found] ` <etPan.5a5a45ec.3309bd20.14e5a@AirmailxGenerated.am> 0 siblings, 2 replies; 7+ messages in thread From: Sebastian Gniazdowski @ 2018-01-13 16:50 UTC (permalink / raw) To: Peter Stephenson, Zsh Users On 13 Dec 2017 at 12:34:08, Peter Stephenson (p.stephenson@samsung.com) wrote: > On Wed, 13 Dec 2017 08:00:51 +0100 > Sebastian Gniazdowski wrote: > > gitout=( "${(@f)"$( "${gitcmd[@]}" )"}" ) > > > > Is it the same? > > It should be, because the count of braces doesn't go to zero between the > first "${" and the last "}" (see the rules I summarised last time). So > only the final double quote causes quoting to end. Going this way, in following braces also don't go zero.. But maybe it's not a bug: arr=( "${(@Q)${(z@):-"a b" c}}" ) print -rl -- "${(@)arr}" a b c arr=( "${(@Q)${(z@):-a\\ b c}}" ) print -rl -- "${(@)arr}" a b c It would be an interesting case because inner quotes wouldn't be a no-op. -- Sebastian Gniazdowski psprint /at/ zdharma.org ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is outer quoting not needed (docs say "redundant")? 2018-01-13 16:50 ` Sebastian Gniazdowski @ 2018-01-13 17:36 ` Bart Schaefer [not found] ` <etPan.5a5a45ec.3309bd20.14e5a@AirmailxGenerated.am> 1 sibling, 0 replies; 7+ messages in thread From: Bart Schaefer @ 2018-01-13 17:36 UTC (permalink / raw) To: Sebastian Gniazdowski; +Cc: Peter Stephenson, Zsh Users On Sat, Jan 13, 2018 at 8:50 AM, Sebastian Gniazdowski <psprint@zdharma.org> wrote: > > arr=( "${(@Q)${(z@):-"a b" c}}" ) > > arr=( "${(@Q)${(z@):-a\\ b c}}" ) These are not the same. Because of the way backslashes behave when they follow the :- operator plus the effect of the (z) flag, the latter is actually the same as arr=( "${(@Q)${(z@):-"a\ b" c}}" ) You can see this if you examine the inner expansion in isolation: % print -rl ${(z@):-"a b" c} a b c % print -rl ${(z@):-a\\ b c} a\ b c ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <etPan.5a5a45ec.3309bd20.14e5a@AirmailxGenerated.am>]
* Re: Is outer quoting not needed (docs say "redundant")? [not found] ` <etPan.5a5a45ec.3309bd20.14e5a@AirmailxGenerated.am> @ 2018-01-14 4:03 ` Sebastian Gniazdowski 0 siblings, 0 replies; 7+ messages in thread From: Sebastian Gniazdowski @ 2018-01-14 4:03 UTC (permalink / raw) To: Bart Schaefer; +Cc: Zsh Users On 13 Jan 2018 at 18:36:39, Bart Schaefer (schaefer@brasslantern.com) wrote: > These are not the same. Because of the way backslashes behave when > they follow the :- operator plus the effect of the (z) flag, the > latter is actually the same as > > arr=( "${(@Q)${(z@):-"a\ b" c}}" ) > > You can see this if you examine the inner expansion in isolation: > > % print -rl ${(z@):-"a b" c} > a > b > c > % print -rl ${(z@):-a\\ b c} > a\ b > c > Thanks. The point about "a\ b" shows that quotes are indeed active. However for final output, it's like " is being merged into quasi-quotes that are between :- and }. -- Sebastian Gniazdowski psprint /at/ zdharma.org ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-01-14 4:03 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CGME20171212135535epcas4p2456a2aed9c9be07c9d461acb602b71e9@epcas4p2.samsung.com> 2017-12-12 13:41 ` Is outer quoting not needed (docs say "redundant")? Sebastian Gniazdowski 2017-12-12 15:00 ` Peter Stephenson 2017-12-13 7:00 ` Sebastian Gniazdowski 2017-12-13 11:34 ` Peter Stephenson 2018-01-13 16:50 ` Sebastian Gniazdowski 2018-01-13 17:36 ` Bart Schaefer [not found] ` <etPan.5a5a45ec.3309bd20.14e5a@AirmailxGenerated.am> 2018-01-14 4:03 ` Sebastian Gniazdowski
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).