1 |
## oils_failures_allowed: 2
|
2 |
|
3 |
|
4 |
shopt -s ysh:upgrade
|
5 |
|
6 |
pp test_ (type(ENV))
|
7 |
#pp test_ (ENV)
|
8 |
|
9 |
# Set by the spec test harness
|
10 |
|
11 |
if (ENV.SH ~~ '*osh') {
|
12 |
echo ok
|
13 |
}
|
14 |
#echo SH=$[ENV.SH]
|
15 |
|
16 |
## STDOUT:
|
17 |
(Str) "Obj"
|
18 |
ok
|
19 |
## END
|
20 |
|
21 |
|
22 |
shopt -s ysh:upgrade
|
23 |
|
24 |
setglobal ENV.PS4 = '%%% '
|
25 |
|
26 |
use $[ENV.REPO_ROOT]/spec/testdata/module2/env.ysh
|
27 |
|
28 |
## STDOUT:
|
29 |
env.ysh
|
30 |
OSH ok
|
31 |
## END
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
osh=$SH # this file is run by OSH
|
37 |
|
38 |
case $osh in
|
39 |
*osh)
|
40 |
echo 'OSH ok'
|
41 |
;;
|
42 |
esac
|
43 |
|
44 |
var ysh = osh.replace('osh', 'ysh')
|
45 |
|
46 |
# NOT exported
|
47 |
$ysh -c 'echo sh=$[getVar("SH")]'
|
48 |
|
49 |
## STDOUT:
|
50 |
OSH ok
|
51 |
sh=null
|
52 |
## END
|
53 |
|
54 |
|
55 |
shopt -s ysh:all
|
56 |
|
57 |
_A=a _B=b env | grep '^_' | sort
|
58 |
|
59 |
## STDOUT:
|
60 |
_A=a
|
61 |
_B=b
|
62 |
## END
|
63 |
|
64 |
|
65 |
|
66 |
f2() {
|
67 |
echo " f2 AA=$AA BB=$BB"
|
68 |
env | egrep 'AA|BB'
|
69 |
}
|
70 |
|
71 |
f1() {
|
72 |
echo "> f1 AA=$AA"
|
73 |
AA=aaaa BB=bb f2
|
74 |
echo "< f1 AA=$AA"
|
75 |
}
|
76 |
|
77 |
AA=a f1
|
78 |
|
79 |
#
|
80 |
# Now with ysh:upgrade
|
81 |
#
|
82 |
|
83 |
shopt --set ysh:upgrade
|
84 |
echo
|
85 |
|
86 |
proc p2 {
|
87 |
echo " p2 AA=$[get(ENV, 'AA')] BB=$[get(ENV, 'BB')]"
|
88 |
env | egrep 'AA|BB'
|
89 |
}
|
90 |
|
91 |
proc p1 {
|
92 |
echo "> p1 AA=$[get(ENV, 'AA')]"
|
93 |
AA=aaaa BB=bb p2
|
94 |
echo "< p1 AA=$[get(ENV, 'AA')]"
|
95 |
}
|
96 |
|
97 |
AA=a p1
|
98 |
|
99 |
#
|
100 |
# Now with ysh:all
|
101 |
#
|
102 |
|
103 |
shopt --set ysh:all
|
104 |
echo
|
105 |
|
106 |
AA=a p1
|
107 |
|
108 |
|
109 |
## STDOUT:
|
110 |
## END
|
111 |
|
112 |
|
113 |
shopt -s ysh:upgrade
|
114 |
|
115 |
setglobal ENV.PYTHONPATH = 'foo'
|
116 |
|
117 |
#pp test_ (ENV)
|
118 |
#export PYTHONPATH=zz
|
119 |
|
120 |
# execute POSIX shell
|
121 |
sh -c 'echo pythonpath=$PYTHONPATH'
|
122 |
|
123 |
## STDOUT:
|
124 |
pythonpath=foo
|
125 |
## END
|
126 |
|
127 |
|
128 |
shopt -s ysh:all
|
129 |
|
130 |
setglobal ENV.ZZ = 'setglobal'
|
131 |
|
132 |
# execute POSIX shell
|
133 |
sh -c 'echo ZZ=$ZZ'
|
134 |
|
135 |
export ZZ='export' # fails
|
136 |
|
137 |
sh -c 'echo ZZ=$ZZ' # not reached
|
138 |
|
139 |
## status: 1
|
140 |
## STDOUT:
|
141 |
ZZ=setglobal
|
142 |
## END
|
143 |
|
144 |
|
145 |
shopt -s ysh:upgrade
|
146 |
|
147 |
export ZZ='export' # fails
|
148 |
|
149 |
sh -c 'echo ZZ=$ZZ' # not reached
|
150 |
|
151 |
setglobal ENV.ZZ = 'setglobal' # this takes precedence
|
152 |
|
153 |
# execute POSIX shell
|
154 |
sh -c 'echo ZZ=$ZZ'
|
155 |
|
156 |
## STDOUT:
|
157 |
ZZ=export
|
158 |
ZZ=setglobal
|
159 |
## END
|
160 |
|
161 |
|
162 |
|
163 |
shopt -s ysh:upgrade
|
164 |
|
165 |
setglobal ENV.PS4 = '%%% '
|
166 |
|
167 |
$[ENV.SH] -c 'set -x; echo 1; echo 2'
|
168 |
|
169 |
## STDOUT:
|
170 |
1
|
171 |
2
|
172 |
## END
|
173 |
## STDERR:
|
174 |
%%% echo 1
|
175 |
%%% echo 2
|
176 |
## END
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
HOME=zz-osh
|
182 |
echo ~/src
|
183 |
|
184 |
shopt --set ysh:upgrade
|
185 |
|
186 |
setvar ENV.HOME = 'ysh-zz'
|
187 |
|
188 |
# TODO: this should consult ENV.HOME
|
189 |
echo ~/src
|
190 |
|
191 |
# not set by spec test framework
|
192 |
#echo $[ENV.HOME]
|
193 |
|
194 |
## STDOUT:
|
195 |
zz-osh/src
|
196 |
ysh-zz/src
|
197 |
## END
|
198 |
|
199 |
|
200 |
|
201 |
shopt --set ysh:upgrade
|
202 |
|
203 |
#export ZZ=zzz
|
204 |
setglobal ENV.ZZ = 'zz'
|
205 |
|
206 |
env sh -c 'echo child ZZ=$ZZ'
|
207 |
|
208 |
exec env sh -c 'echo exec ZZ=$ZZ'
|
209 |
|
210 |
## STDOUT:
|
211 |
child ZZ=zz
|
212 |
exec ZZ=zz
|
213 |
## END
|