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

Re: for loop 'bad math expression'



I know and expect that $((()) has its 
internal grammar.  But 'let' seems ... naked ... for lack of a better word and it's a strain on grammatical rigor that it gets special, invisible favors.

Well, it doesn't, really. Grammar-wise, let is treated as a normal command, which is why you need quoting to use special characters or white space with it. The ((...)) construct was added to the shell (and described in the KornShell book) as effectively a version of let that is quoted for you - that's where the special parsing comes in. let itself doesn't have that. 

It does evaluate its arguments in an arithmetic context, and is one of the main ways to achieve that effect, but it's not the only one, or even the only one outside ((...)).  You've seen it kick in for variables declared as integers; it also shows up in array subscripts:

zsh% ary=(a b c d e); i=2; j=1; k="i + j"
zsh% echo $ary[$k]
c


--
Mark J. Reed <markjreed@xxxxxxxxx>


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