1 |
## compare_shells: bash
|
2 |
|
3 |
|
4 |
# Notes:
|
5 |
# - OSH prompt goes to stdout and bash goes to stderr
|
6 |
# - This test seems to fail on the system bash, but succeeds with spec-bin/bash
|
7 |
echo 'echo foo' | PS1='[prompt] ' $SH --rcfile /dev/null -i >out.txt 2>err.txt
|
8 |
fgrep -q '[prompt]' out.txt err.txt
|
9 |
echo match=$?
|
10 |
## STDOUT:
|
11 |
match=0
|
12 |
## END
|
13 |
|
14 |
|
15 |
PS1='\[foo\]\$'
|
16 |
echo "${PS1@P}"
|
17 |
## STDOUT:
|
18 |
foo$
|
19 |
## END
|
20 |
|
21 |
|
22 |
PS1='\a\e\r\n'
|
23 |
echo "${PS1@P}"
|
24 |
## stdout-json: "\u0007\u001b\r\n\n"
|
25 |
|
26 |
|
27 |
# NOTE: This might be broken for # but it's hard to tell since we don't have
|
28 |
# root. Could inject __TEST_EUID or something.
|
29 |
PS1='$'
|
30 |
echo "${PS1@P}"
|
31 |
PS1='\$'
|
32 |
echo "${PS1@P}"
|
33 |
PS1='\\$'
|
34 |
echo "${PS1@P}"
|
35 |
PS1='\\\$'
|
36 |
echo "${PS1@P}"
|
37 |
PS1='\\\\$'
|
38 |
echo "${PS1@P}"
|
39 |
## STDOUT:
|
40 |
$
|
41 |
$
|
42 |
$
|
43 |
\$
|
44 |
\$
|
45 |
## END
|
46 |
|
47 |
|
48 |
x='\'
|
49 |
y='h'
|
50 |
PS1='$x$y'
|
51 |
echo "${PS1@P}"
|
52 |
## STDOUT:
|
53 |
\h
|
54 |
## END
|
55 |
|
56 |
|
57 |
foo=foo_value
|
58 |
dir=$TMP/'$foo' # Directory name with a dollar!
|
59 |
mkdir -p $dir
|
60 |
cd $dir
|
61 |
PS1='\w $foo'
|
62 |
test "${PS1@P}" = "$PWD foo_value"
|
63 |
echo status=$?
|
64 |
## STDOUT:
|
65 |
status=0
|
66 |
## END
|
67 |
|
68 |
|
69 |
PS1='\1004$'
|
70 |
echo "${PS1@P}"
|
71 |
## STDOUT:
|
72 |
@4$
|
73 |
## END
|
74 |
|
75 |
|
76 |
PS1='[\045]'
|
77 |
echo "${PS1@P}"
|
78 |
## STDOUT:
|
79 |
[%]
|
80 |
## END
|
81 |
|
82 |
|
83 |
PS1='\555$'
|
84 |
echo "${PS1@P}"
|
85 |
## STDOUT:
|
86 |
m$
|
87 |
## END
|
88 |
|
89 |
|
90 |
PS1='[\x55]'
|
91 |
echo "${PS1@P}"
|
92 |
## STDOUT:
|
93 |
[\x55]
|
94 |
## END
|
95 |
|
96 |
|
97 |
PS1='\'
|
98 |
echo "${PS1@P}"
|
99 |
## BUG bash stdout-json: "\\\u0002\n"
|
100 |
## STDOUT:
|
101 |
\
|
102 |
## END
|
103 |
|
104 |
|
105 |
PS1='\\'
|
106 |
echo "${PS1@P}"
|
107 |
## BUG bash stdout-json: "\\\u0002\n"
|
108 |
## STDOUT:
|
109 |
\
|
110 |
## END
|
111 |
|
112 |
|
113 |
PS1='[\0455]'
|
114 |
echo "${PS1@P}"
|
115 |
## STDOUT:
|
116 |
[%5]
|
117 |
## END
|
118 |
|
119 |
|
120 |
PS1='[\u0001]'
|
121 |
USER=$(whoami)
|
122 |
test "${PS1@P}" = "[${USER}0001]"
|
123 |
echo status=$?
|
124 |
## STDOUT:
|
125 |
status=0
|
126 |
## END
|
127 |
|
128 |
|
129 |
PS1='$ '
|
130 |
echo "${PS1@P}"
|
131 |
## STDOUT:
|
132 |
$
|
133 |
## END
|
134 |
|
135 |
|
136 |
|
137 |
# NOTE: This test is not hermetic. On my machine the short and long host name
|
138 |
# are the same.
|
139 |
|
140 |
PS1='\h '
|
141 |
test "${PS1@P}" = "$(hostname -s) " # short name
|
142 |
echo status=$?
|
143 |
PS1='\H '
|
144 |
test "${PS1@P}" = "$(hostname) "
|
145 |
echo status=$?
|
146 |
## STDOUT:
|
147 |
status=0
|
148 |
status=0
|
149 |
## END
|
150 |
|
151 |
|
152 |
PS1='\u '
|
153 |
USER=$(whoami)
|
154 |
test "${PS1@P}" = "${USER} "
|
155 |
echo status=$?
|
156 |
## STDOUT:
|
157 |
status=0
|
158 |
## END
|
159 |
|
160 |
|
161 |
PS1='\w '
|
162 |
test "${PS1@P}" = "${PWD} "
|
163 |
echo status=$?
|
164 |
## STDOUT:
|
165 |
status=0
|
166 |
## END
|
167 |
|
168 |
|
169 |
PS1='\W '
|
170 |
test "${PS1@P}" = "$(basename $PWD) "
|
171 |
echo status=$?
|
172 |
## STDOUT:
|
173 |
status=0
|
174 |
## END
|
175 |
|
176 |
|
177 |
PS1='foo \A bar'
|
178 |
echo "${PS1@P}" | egrep -q 'foo [0-9][0-9]:[0-9][0-9] bar'
|
179 |
echo matched=$?
|
180 |
## STDOUT:
|
181 |
matched=0
|
182 |
## END
|
183 |
|
184 |
|
185 |
PS1='foo \D{%H:%M} bar'
|
186 |
echo "${PS1@P}" | egrep -q 'foo [0-9][0-9]:[0-9][0-9] bar'
|
187 |
echo matched=$?
|
188 |
|
189 |
PS1='foo \D{%H:%M:%S} bar'
|
190 |
echo "${PS1@P}" | egrep -q 'foo [0-9][0-9]:[0-9][0-9]:[0-9][0-9] bar'
|
191 |
echo matched=$?
|
192 |
|
193 |
## STDOUT:
|
194 |
matched=0
|
195 |
matched=0
|
196 |
## END
|
197 |
|
198 |
|
199 |
|
200 |
# In bash y.tab.c uses %X when string is empty
|
201 |
# This doesn't seem to match exactly, but meh for now.
|
202 |
|
203 |
PS1='foo \D{} bar'
|
204 |
echo "${PS1@P}" | egrep -q '^foo [0-9][0-9]:[0-9][0-9]:[0-9][0-9]( ..)? bar$'
|
205 |
echo matched=$?
|
206 |
## STDOUT:
|
207 |
matched=0
|
208 |
## END
|
209 |
|
210 |
|
211 |
PS1='foo \s bar'
|
212 |
echo "${PS1@P}" | egrep -q '^foo (bash|osh) bar$'
|
213 |
echo match=$?
|
214 |
|
215 |
PS1='foo \v bar'
|
216 |
echo "${PS1@P}" | egrep -q '^foo [0-9.]+ bar$'
|
217 |
echo match=$?
|
218 |
|
219 |
## STDOUT:
|
220 |
match=0
|
221 |
match=0
|
222 |
## END
|
223 |
|
224 |
|
225 |
$SH -c 'echo ${@@P}' dummy a b c
|
226 |
echo status=$?
|
227 |
$SH -c 'echo ${*@P}' dummy a b c
|
228 |
echo status=$?
|
229 |
$SH -c 'a=(x y); echo ${a@P}' dummy a b c
|
230 |
echo status=$?
|
231 |
## STDOUT:
|
232 |
a b c
|
233 |
status=0
|
234 |
a b c
|
235 |
status=0
|
236 |
x
|
237 |
status=0
|
238 |
## END
|
239 |
## OK osh STDOUT:
|
240 |
status=1
|
241 |
status=1
|
242 |
x
|
243 |
status=0
|
244 |
## END
|
245 |
|
246 |
|
247 |
#flags='--norc --noprofile'
|
248 |
flags='--rcfile /dev/null'
|
249 |
|
250 |
$SH $flags -i -c 'echo "_${PS1}_"'
|
251 |
|
252 |
## STDOUT:
|
253 |
_\s-\v\$ _
|
254 |
## END
|
255 |
|