File: arith9.sub

package info (click to toggle)
bash 5.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 43,860 kB
  • sloc: ansic: 134,738; sh: 8,866; yacc: 5,966; makefile: 4,697; perl: 4,105; asm: 48; awk: 23; sed: 16
file content (38 lines) | stat: -rw-r--r-- 578 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# test expression evaluation with unset variables
set -u

( echo $(( a > 4 )) ; echo after 1 )	# error
( echo $(( a[0] > 4 )); echo after 2)	# error

set +u
( echo $(( a > 4 )) ; echo after 3 $? )
( echo $(( a[0] > 4 )); echo after 4 $?)

# this is a recursion stack error
a=b
b=a
echo $(( a + 7 ))

# make sure command printing works for arithmetic expansions and commands
set -x
var=42

echo $(( $var ))
echo $?

echo $(( $null ))
echo $?

(( $var ))
echo $?

(( $null ))
echo $?

set +x

# invalid expressions in different cases
x=4+
declare -i x
x+=7 y=4
echo x = $x y = $y