Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: priority problem of ":|" and ":*"

On Dec 26,  6:09pm, Han Pingtian wrote:
} Subject: Re: priority problem of ":|" and ":*"
} On Wed, Dec 26, 2012 at 01:10:19AM -0800, Bart Schaefer wrote:
} > And in fact poring through the code it appears that rule 5 double-quoted
} > joining is explicitly SKIPPED when the length is requested:
} But I think ":|" doesn't skip the double-quoted, so the "#" would get the
} length of the result of ":|", because "#"'s priority is lower than
} ":|"'s. Or when running in double-quoted, "#" will has a higher priority
} ?

Unfortunately you can't think of the parameter flags and modifiers like
arithmetic operators.  They don't have well-defined precedences.  So it
is almost meaningless to speak of # or :| having relative "priority."
The numbering of the "rules" for parameter expansion in the manual
describes the order in which operations are applied, and sometimes the
rules do not cover all possible combinations.

Those "rules" were derived after the fact by code examination, not made
up ahead of time as a specification for how the code is suppose to work.
In situations where the code and the manual disagree, code is definitive
unless we are able to determine that (a) the description in the manual
is more sensible and (b) nothing is going to break if we revise the code
to match the documentation.  I don't believe we've established (b) here.

In this case rule 5 should have mentioned an exception for the # length
expression as it does for the (@) array flag, and the description of SPEC
in the ${#SPEC} documentation might have been qualified to explain that
surrounding double-quotes are intentionally prevented from altering the
semantics of the length calculation.

To get what you expected, you must use a nested substitution.

Messages sorted by: Reverse Date, Date, Thread, Author