OILS / spec / glob-bash.test.sh View on Github | oils.pub

144 lines, 75 significant
1## compare_shells: bash
2
3#### shopt -s nullglob
4argv.py _tmp/spec-tmp/*.nonexistent
5shopt -s nullglob
6argv.py _tmp/spec-tmp/*.nonexistent
7## STDOUT:
8['_tmp/spec-tmp/*.nonexistent']
9[]
10## END
11## N-I dash/mksh/ash STDOUT:
12['_tmp/spec-tmp/*.nonexistent']
13['_tmp/spec-tmp/*.nonexistent']
14## END
15
16#### shopt -s failglob in command context
17argv.py *.ZZ
18shopt -s failglob
19argv.py *.ZZ # nothing is printed, not []
20echo status=$?
21## STDOUT:
22['*.ZZ']
23status=1
24## END
25## N-I dash/mksh/ash STDOUT:
26['*.ZZ']
27['*.ZZ']
28status=0
29## END
30
31#### shopt -s failglob in loop context
32for x in *.ZZ; do echo $x; done
33echo status=$?
34shopt -s failglob
35for x in *.ZZ; do echo $x; done
36echo status=$?
37## STDOUT:
38*.ZZ
39status=0
40status=1
41## END
42## N-I dash/mksh/ash STDOUT:
43*.ZZ
44status=0
45*.ZZ
46status=0
47## END
48
49#### shopt -s failglob in array literal context
50myarr=(*.ZZ)
51echo "${myarr[@]}"
52shopt -s failglob
53myarr=(*.ZZ)
54echo status=$?
55## STDOUT:
56*.ZZ
57status=1
58## END
59## N-I mksh STDOUT:
60*.ZZ
61status=0
62## END
63## N-I dash/ash stdout-json: ""
64## N-I dash/ash status: 2
65
66#### shopt -s failglob exits properly in command context with set -e
67set -e
68argv.py *.ZZ
69shopt -s failglob
70argv.py *.ZZ
71echo status=$?
72## STDOUT:
73['*.ZZ']
74## END
75## status: 1
76## N-I dash/mksh/ash STDOUT:
77['*.ZZ']
78## END
79## N-I dash/mksh/ash status: 127
80
81#### shopt -s failglob exits properly in loop context with set -e
82set -e
83for x in *.ZZ; do echo $x; done
84echo status=$?
85
86shopt -s failglob
87for x in *.ZZ; do echo $x; done
88echo status=$?
89
90## status: 1
91## STDOUT:
92*.ZZ
93status=0
94## END
95
96## N-I dash/mksh/ash status: 127
97## N-I dash/mksh/ash STDOUT:
98*.ZZ
99status=0
100## END
101
102#### shopt -s failglob behavior on single line with semicolon
103# bash behaves differently when commands are separated by a semicolon than when
104# separated by a newline. This behavior doesn't make sense or seem to be
105# intentional, so osh does not mimic it.
106
107shopt -s failglob
108echo *.ZZ; echo status=$? # bash doesn't execute the second part!
109echo *.ZZ
110echo status=$? # bash executes this
111
112## STDOUT:
113status=1
114## END
115
116## OK osh STDOUT:
117status=1
118status=1
119## END
120
121## N-I dash/mksh/ash STDOUT:
122*.ZZ
123status=0
124*.ZZ
125status=0
126## END
127
128#### dotglob (bash option that dashglob is roughly consistent with)
129mkdir -p $TMP/dotglob
130cd $TMP/dotglob
131touch .foorc other
132
133echo *
134shopt -s dotglob
135echo * | sort
136## STDOUT:
137other
138.foorc other
139## END
140## N-I dash/mksh/ash STDOUT:
141other
142other
143## END
144