1 ## compare_shells: dash bash mksh
2
3 # Some nonsensical combinations which can all be detected at PARSE TIME.
4 # All shells allow these, but right now OSH disallowed.
5 # TODO: Run the parser on your whole corpus, and then if there are no errors,
6 # you should make OSH the OK behavior, and others are OK.
7
8 #### Prefix env on assignment
9 f() {
10 # NOTE: local treated like a special builtin!
11 E=env local v=var
12 echo $E $v
13 }
14 f
15 ## status: 0
16 ## stdout: env var
17 ## OK bash stdout: var
18
19 #### Redirect on assignment (enabled 7/2019)
20 f() {
21 # NOTE: local treated like a special builtin!
22 local E=env > _tmp/r.txt
23 }
24 rm -f _tmp/r.txt
25 f
26 test -f _tmp/r.txt && echo REDIRECTED
27 ## status: 0
28 ## stdout: REDIRECTED
29
30 #### Prefix env on control flow
31 for x in a b c; do
32 echo $x
33 E=env break
34 done
35 ## status: 0
36 ## stdout: a
37 ## OK osh status: 2
38 ## OK osh stdout-json: ""
39
40 #### Redirect on control flow (ignored in OSH)
41 rm -f _tmp/r.txt
42 for x in a b c; do
43 break > _tmp/r.txt
44 done
45 if test -f _tmp/r.txt; then
46 echo REDIRECTED
47 else
48 echo NO
49 fi
50 ## status: 0
51 ## stdout: REDIRECTED
52 ## OK osh stdout: NO
53
54 #### Redirect on control flow with oil:all (parse_ignored)
55 shopt -s oil:all
56 rm -f _tmp/r.txt
57 for x in a b c; do
58 break > _tmp/r.txt
59 done
60 test -f _tmp/r.txt && echo REDIRECTED
61 ## status: 0
62 ## stdout: REDIRECTED
63 ## OK osh status: 2
64 ## OK osh stdout-json: ""