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

Re: Arith parsing bug with minus after $#



Peter Stephenson schreef op 29-05-15 om 17:02:
> 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.

Ah, yes... ${#-} is the length in characters of $-, the shell options
that are set. Before 'emulate sh', the length of $- is 8, and after,
it's 4. That explains the results I got.

The fix is working; thanks yet again.

- M.



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