1 #### OSH behavior
2 x=1
3 echo status=$?
4 echo x=$x
5
6 y = 2
7 echo status=$?
8 echo y=$y
9 ## STDOUT:
10 status=0
11 x=1
12 status=127
13 y=
14 ## END
15
16 #### ysh:upgrade behavior
17 shopt --set ysh:upgrade
18
19 # allow errors
20 set +o errexit +o nounset
21
22 x=1
23 echo status=$?
24 echo x=$x
25
26 y = 2
27 echo status=$?
28 echo y=$y
29 ## status: 2
30 ## STDOUT:
31 status=0
32 x=1
33 ## END
34
35 #### x=y is allowed at the top level
36 shopt --set ysh:all
37
38 # allow errors
39 set +o errexit +o nounset
40
41 x=42
42 echo status=$?
43 echo x=$x
44
45 y = 2 # fails because = is ambiguous
46 echo status=$?
47 echo y=$y
48
49 ## status: 2
50 ## STDOUT:
51 status=0
52 x=42
53 ## END
54
55
56 #### parse_equals: allows bare assignment in Caps blocks
57 shopt --set parse_proc parse_brace parse_equals
58
59 proc Rule {
60 true
61 }
62
63 Rule {
64 x = 1 + 2*3
65 }
66 echo x=$x
67
68 # still allowed since we didn't unset parse_sh_assign
69 y=foo
70 echo y=$y
71
72 ## STDOUT:
73 x=
74 y=foo
75 ## END
76
77 #### bare assignment inside Hay blocks
78
79 shopt --set ysh:all
80
81 hay define Package
82
83 # problem: we would allow it here, which is weird
84
85 proc p {
86 var x = 42
87 }
88
89 cd /tmp {
90 var x = 'hi'
91 }
92
93 hay eval :result {
94 Package {
95 version = 1
96 }
97 }
98
99 var x = 1
100 echo "x is $x"
101
102 ## STDOUT:
103 x is 1
104 ## END
105
106