help-bash
[Top][All Lists]
Advanced

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

Exclusion of `${##}` from the doc of `${parameter#word}`?


From: Peng Yu
Subject: Exclusion of `${##}` from the doc of `${parameter#word}`?
Date: Sat, 8 May 2021 23:53:49 -0500

`${##}` could be interpreted as `${parameter#word}` according to the
manual, where parameter is `#` and word is empty.

       ${parameter#word}
       ${parameter##word}
              Remove  matching prefix pattern.  The word is expanded
to produce a pattern just as in path-
              name expansion, and matched  against  the  expanded
value  of  parameter  using  the  rules
              described  under  Pattern Matching below.  If the
pattern matches the beginning of the value
              of parameter, then the result of the expansion is the
expanded value of parameter  with  the
              shortest matching pattern (the ``#'' case) or the
longest matching pattern (the ``##'' case)
              deleted.  If parameter is @ or *, the pattern removal
operation is  applied  to  each  posi-
              tional parameter in turn, and the expansion is the
resultant list.  If parameter is an array
              variable subscripted with @ or *, the pattern removal
operation is applied to each member of
              the array in turn, and the expansion is the resultant list.

But it actually just counts the number of characters of `$#` for which
the following rule applies. It seems that the manual is ambiguous on
this specific case. Is it so?

       ${#parameter}
              Parameter  length.   The  length in characters of the
value of parameter is substituted.  If
              parameter is * or @, the value substituted is  the
number  of  positional  parameters.   If
              parameter  is  an  array  name subscripted by * or @,
the value substituted is the number of
              elements in the array.  If parameter is an indexed array
name subscripted by a negative num-
              ber, that number is interpreted as relative to one
greater than the maximum index of parame-
              ter, so negative indices count back from the end of the
array, and an index of -1 references
              the last element.

$ set -- {a..z}; echo ${##}
2

-- 
Regards,
Peng



reply via email to

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