OILS / spec / array-basic.test.sh View on Github | oilshell.org

45 lines, 16 significant
1## compare_shells: bash mksh zsh
2
3# Common between bash/zsh
4
5#### "${a[@]}" and "${a[*]}"
6a=(1 '2 3')
7argv.py "${a[@]}" "${a[*]}"
8## stdout: ['1', '2 3', '1 2 3']
9
10#### ${a[@]} and ${a[*]}
11a=(1 '2 3')
12argv.py ${a[@]} ${a[*]}
13## STDOUT:
14['1', '2', '3', '1', '2', '3']
15## END
16## BUG zsh STDOUT:
17['1', '2 3', '1', '2 3']
18## END
19
20#### 4 ways to interpolate empty array
21argv.py 1 "${a[@]}" 2 ${a[@]} 3 "${a[*]}" 4 ${a[*]} 5
22## STDOUT:
23['1', '2', '3', '', '4', '5']
24## END
25
26## BUG zsh STDOUT:
27['1', '', '2', '3', '', '4', '5']
28## END
29
30#### empty array
31empty=()
32argv.py "${empty[@]}"
33## STDOUT:
34[]
35## END
36
37#### Empty array with :-
38empty=()
39argv.py ${empty[@]:-not one} "${empty[@]:-not one}"
40## STDOUT:
41['not', 'one', 'not one']
42## END
43## BUG zsh STDOUT:
44['not one', 'not one']
45## END