bash man not followed: ((?:)) requires paranthesis on third operand to accept vars
Code:
echo $((myvar<5?myvar=7:myvar=myvar-1)) Code:
echo $((myvar<5?myvar=7:(myvar=myvar-1))) Am I right, is this really a bug? In fact, it requires parantheses on the third operand to accept var=. |
No it is not a bug. Did you read the error messages from your first code?
You are missing he point that this construct is being strict about what it is doing. You can look at your first one like so: Code:
echo $((myvar<5?myvar=7:myvar=myvar-1)) be assigned to an expression. Your second version of course overcomes this by placing parenthesis around the assignment and hence it is performed prior to returning the value. Strictly speaking you did not have to go through all this anyway: Code:
echo $((myvar = myvar<5?7:--myvar)) |
Quote:
Still I don't understand why is "=" not treated just like any other operator, for example like "<" or "--", since they do belong to the same list under "ARITHMETIC EVALUATION" in bash man. What makes ?: end before it meets "))"? "?:" has higher precedence than "=". |
Maybe this table can help.
Ultimately each part of the trinary operator must be complete, but you will see from the table that the '=' is lower in precedence |
All times are GMT -5. The time now is 09:09 PM. |