File: arith-precedence1.tests

package info (click to toggle)
busybox 1%3A1.37.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,684 kB
  • sloc: ansic: 190,169; sh: 10,414; cpp: 1,428; makefile: 1,005; asm: 798; yacc: 570; lex: 355; perl: 334; python: 112; awk: 29
file content (15 lines) | stat: -rwxr-xr-x 547 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
exec 2>&1
# bash documentation says that precedence order is:
#  ...
#  expr ? expr1 : expr2
#  = *= /= %= += -= <<= >>= &= ^= |=
#  exprA , exprB
# but in practice, the rules for expr1 and expr2 are different:
# assignments and commas in expr1 have higher precedence than :?,
# but in expr2 they haven't:
# "v ? 1,2 : 3,4" is parsed as "(v ? (1,2) : 3),4"
# "v ? a=2 : b=4" is parsed as "(v ? (a=1) : b)=4" (thus, this is a syntax error)
echo 4:$((0 ? 1,2 : 3,4))
echo 4:$((1 ? 1,2 : 3,4))
echo 4:"$((0 ? 1,2 : 3,4))"
echo 4:"$((1 ? 1,2 : 3,4))"