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

Re: Arith parsing bug with minus after $#



On Fri, May 29, 2015 at 8:02 AM, Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
> On Thu, 28 May 2015 21:42:41 +0200
> Martijn Dekker <martijn@xxxxxxxx> wrote:
>> % set --
>> % echo $#
>> 0
>> % echo $(($#-1))
>> 41
>
> That's not a compatibility issue, that's just plain weird.  I don't know
> the POSIX terminology.
>
> The problem is the overloading of "#" --- the test to establish what to
> do with it is trying too hard to resolve to ${#-}, which is a valid
> substitution, because it hasn't taken into account that there are no
> braces.  So what you're seeing is ${#-}1.

Incidentally, here is a few-years-old austin-group thread that is related:

http://thread.gmane.org/gmane.comp.standards.posix.austin.general/3784



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