OILS / spec / builtin-misc.test.sh View on Github | oilshell.org

161 lines, 69 significant
1## oils_failures_allowed: 0
2## compare_shells: dash bash mksh zsh
3
4#### history builtin usage
5history
6echo status=$?
7history +5 # hm bash considers this valid
8echo status=$?
9history -5 # invalid flag
10echo status=$?
11history f
12echo status=$?
13history too many args
14echo status=$?
15## status: 0
16## STDOUT:
17status=0
18status=0
19status=2
20status=2
21status=2
22## END
23## OK bash STDOUT:
24status=0
25status=0
26status=2
27status=1
28status=1
29## END
30## BUG zsh/mksh STDOUT:
31status=1
32status=1
33status=1
34status=1
35status=1
36## END
37## N-I dash STDOUT:
38status=127
39status=127
40status=127
41status=127
42status=127
43## END
44
45
46#### Print shell strings with weird chars: set and printf %q and ${x@Q}
47
48# bash declare -p will print binary data, which makes this invalid UTF-8!
49foo=$(/bin/echo -e 'a\nb\xffc'\'d)
50
51# let's test the easier \x01, which doesn't give bash problems
52foo=$(/bin/echo -e 'a\nb\x01c'\'d)
53
54# dash:
55# only supports 'set'; prints it on multiple lines with binary data
56# switches to "'" for single quotes, not \'
57# zsh:
58# print binary data all the time, except for printf %q
59# does print $'' strings
60# mksh:
61# prints binary data for @Q
62# prints $'' strings
63
64# All are very inconsistent.
65
66case $SH in dash|mksh|zsh) return ;; esac
67
68
69set | grep -A1 foo
70
71# Will print multi-line and binary data literally!
72#declare -p foo
73
74printf 'pf %q\n' "$foo"
75
76echo '@Q ' ${foo@Q}
77
78## STDOUT:
79foo=$'a\nb\u0001c\'d'
80pf $'a\nb\u0001c\'d'
81@Q $'a\nb\u0001c\'d'
82## END
83
84## OK bash STDOUT:
85foo=$'a\nb\001c\'d'
86pf $'a\nb\001c\'d'
87@Q $'a\nb\001c\'d'
88## END
89
90## OK dash/mksh/zsh STDOUT:
91## END
92
93#### Print shell strings with normal chars: set and printf %q and ${x@Q}
94
95# There are variations on whether quotes are printed
96
97case $SH in dash|zsh) return ;; esac
98
99foo=spam
100
101set | grep -A1 foo
102
103# Will print multi-line and binary data literally!
104typeset -p foo
105
106printf 'pf %q\n' "$foo"
107
108echo '@Q ' ${foo@Q}
109
110## STDOUT:
111foo=spam
112declare -- foo=spam
113pf spam
114@Q spam
115## END
116
117
118## OK bash STDOUT:
119foo=spam
120declare -- foo="spam"
121pf spam
122@Q 'spam'
123## END
124
125## OK mksh STDOUT:
126foo=spam
127typeset foo=spam
128pf spam
129@Q spam
130## END
131
132## N-I dash/zsh STDOUT:
133## END
134
135
136
137#### time pipeline
138time echo hi | wc -c
139## stdout: 3
140## status: 0
141
142#### shift
143set -- 1 2 3 4
144shift
145echo "$@"
146shift 2
147echo "$@"
148## stdout-json: "2 3 4\n4\n"
149## status: 0
150
151#### Shifting too far
152set -- 1
153shift 2
154## status: 1
155## OK dash status: 2
156
157#### Invalid shift argument
158shift ZZZ
159## status: 2
160## OK bash status: 1
161## BUG mksh/zsh status: 0