diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-06-13 18:27:19 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-06-14 00:41:18 +0200 |
commit | 8acbf31708779e7ad559775c9db4ebd7a962be33 (patch) | |
tree | 6ebbb1943faa703f53257b6b64c3426e9cf647d6 /shell/ash_test/ash-arith | |
parent | 373f64eef3cc121d7531522ef654feb0a8068d5a (diff) | |
download | busybox-w32-8acbf31708779e7ad559775c9db4ebd7a962be33.tar.gz busybox-w32-8acbf31708779e7ad559775c9db4ebd7a962be33.tar.bz2 busybox-w32-8acbf31708779e7ad559775c9db4ebd7a962be33.zip |
shell/math: document ternary ?: op's weirdness, add code comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash_test/ash-arith')
-rw-r--r-- | shell/ash_test/ash-arith/arith-precedence1.right | 3 | ||||
-rwxr-xr-x | shell/ash_test/ash-arith/arith-precedence1.tests | 13 |
2 files changed, 16 insertions, 0 deletions
diff --git a/shell/ash_test/ash-arith/arith-precedence1.right b/shell/ash_test/ash-arith/arith-precedence1.right index 7f407b5d2..3f9320a13 100644 --- a/shell/ash_test/ash-arith/arith-precedence1.right +++ b/shell/ash_test/ash-arith/arith-precedence1.right | |||
@@ -1 +1,4 @@ | |||
1 | 4:4 | 1 | 4:4 |
2 | 4:4 | ||
3 | 4:4 | ||
4 | 4:4 | ||
diff --git a/shell/ash_test/ash-arith/arith-precedence1.tests b/shell/ash_test/ash-arith/arith-precedence1.tests index 964ae4ee2..bfef05292 100755 --- a/shell/ash_test/ash-arith/arith-precedence1.tests +++ b/shell/ash_test/ash-arith/arith-precedence1.tests | |||
@@ -1,2 +1,15 @@ | |||
1 | exec 2>&1 | 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)) | ||
2 | echo 4:"$((0 ? 1,2 : 3,4))" | 14 | echo 4:"$((0 ? 1,2 : 3,4))" |
15 | echo 4:"$((1 ? 1,2 : 3,4))" | ||