Hi, I have recently been looking at the POSIX Shell Command Language specification [1] and trying to understand how shells parse their input. One thing I am currently looking at is arithmetic expansion. I did some tests with Bash, and one thing seemed curious to me:
In the Bash Reference Manual [2], the operator precedence is listed as: 1. post-in/decrement 2. pre-in/decrement 3. unary +/- (etc...) I was wondering about the implications of the ordering of the pre/post-in/decrement operators for parsing. I came up with the following expression to test this: $ TEST=5; echo $((--TEST+++3)) # outputs 7 However, due to the documented operator precedence, I would have expected that expression to be equal to: $ TEST=5; echo $((--(TEST++)+3)) # outputs 8 Instead, though, it seems to be equal this one: $ TEST=5; echo $(((--TEST)+++3)) # outputs 7 So my qestions are: Is this a bug? Or is this something that can't be resolved due ambiguities in the grammar? Or what's going on here at all? and: Is there an expression where the precedence of the postfix operator actually comes into play? I am aware that this is a very fabricated example, I am just trying to understand the boundaries of the grammar here. Any enlightenment would be highly appreciated :) Thanks a lot, Conrad [1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.htm [2] https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic