arith-precedence1.tests 547 B

123456789101112131415
  1. exec 2>&1
  2. # bash documentation says that precedence order is:
  3. # ...
  4. # expr ? expr1 : expr2
  5. # = *= /= %= += -= <<= >>= &= ^= |=
  6. # exprA , exprB
  7. # but in practice, the rules for expr1 and expr2 are different:
  8. # assignments and commas in expr1 have higher precedence than :?,
  9. # but in expr2 they haven't:
  10. # "v ? 1,2 : 3,4" is parsed as "(v ? (1,2) : 3),4"
  11. # "v ? a=2 : b=4" is parsed as "(v ? (a=1) : b)=4" (thus, this is a syntax error)
  12. echo 4:$((0 ? 1,2 : 3,4))
  13. echo 4:$((1 ? 1,2 : 3,4))
  14. echo 4:"$((0 ? 1,2 : 3,4))"
  15. echo 4:"$((1 ? 1,2 : 3,4))"