1 ## oils_failures_allowed: 0
2 ## compare_shells: dash bash mksh zsh
3
4 #### history builtin usage
5 history
6 echo status=$?
7 history +5 # hm bash considers this valid
8 echo status=$?
9 history -5 # invalid flag
10 echo status=$?
11 history f
12 echo status=$?
13 history too many args
14 echo status=$?
15 ## status: 0
16 ## STDOUT:
17 status=0
18 status=0
19 status=2
20 status=2
21 status=2
22 ## END
23 ## OK bash STDOUT:
24 status=0
25 status=0
26 status=2
27 status=1
28 status=1
29 ## END
30 ## BUG zsh/mksh STDOUT:
31 status=1
32 status=1
33 status=1
34 status=1
35 status=1
36 ## END
37 ## N-I dash STDOUT:
38 status=127
39 status=127
40 status=127
41 status=127
42 status=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!
49 foo=$(/bin/echo -e 'a\nb\xffc'\'d)
50
51 # let's test the easier \x01, which doesn't give bash problems
52 foo=$(/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
66 case $SH in dash|mksh|zsh) return ;; esac
67
68
69 set | grep -A1 foo
70
71 # Will print multi-line and binary data literally!
72 #declare -p foo
73
74 printf 'pf %q\n' "$foo"
75
76 echo '@Q ' ${foo@Q}
77
78 ## STDOUT:
79 foo=$'a\nb\u0001c\'d'
80 pf $'a\nb\u0001c\'d'
81 @Q $'a\nb\u0001c\'d'
82 ## END
83
84 ## OK bash STDOUT:
85 foo=$'a\nb\001c\'d'
86 pf $'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
97 case $SH in dash|zsh) return ;; esac
98
99 foo=spam
100
101 set | grep -A1 foo
102
103 # Will print multi-line and binary data literally!
104 typeset -p foo
105
106 printf 'pf %q\n' "$foo"
107
108 echo '@Q ' ${foo@Q}
109
110 ## STDOUT:
111 foo=spam
112 declare -- foo=spam
113 pf spam
114 @Q spam
115 ## END
116
117
118 ## OK bash STDOUT:
119 foo=spam
120 declare -- foo="spam"
121 pf spam
122 @Q 'spam'
123 ## END
124
125 ## OK mksh STDOUT:
126 foo=spam
127 typeset foo=spam
128 pf spam
129 @Q spam
130 ## END
131
132 ## N-I dash/zsh STDOUT:
133 ## END
134
135
136
137 #### time pipeline
138 time echo hi | wc -c
139 ## stdout: 3
140 ## status: 0
141
142 #### shift
143 set -- 1 2 3 4
144 shift
145 echo "$@"
146 shift 2
147 echo "$@"
148 ## stdout-json: "2 3 4\n4\n"
149 ## status: 0
150
151 #### Shifting too far
152 set -- 1
153 shift 2
154 ## status: 1
155 ## OK dash status: 2
156
157 #### Invalid shift argument
158 shift ZZZ
159 ## status: 2
160 ## OK bash status: 1
161 ## BUG mksh/zsh status: 0