1 ## tags: interactive
2 ## compare_shells: bash dash mksh zsh
3
4 #### sh -c
5 $SH -c 'echo hi'
6 ## stdout: hi
7 ## status: 0
8
9 #### empty -c input
10 # had a bug here
11 $SH -c ''
12 ## stdout-json: ""
13 ## status: 0
14
15 #### sh +c is accepted
16 $SH +c 'echo hi'
17 ## stdout: hi
18 ## status: 0
19 ## N-I mksh/yash stdout-json: ""
20 ## N-I mksh/yash status: 127
21
22 #### empty stdin
23 # had a bug here
24 echo -n '' | $SH
25 ## stdout-json: ""
26 ## status: 0
27
28 #### shell obeys --help (regression for OSH)
29 n=$($SH --help | wc -l)
30 if test $n -gt 0; then
31 echo yes
32 fi
33 ## STDOUT:
34 yes
35 ## END
36 ## N-I dash/mksh stdout-json: ""
37
38 #### args are passed
39 $SH -c 'argv.py "$@"' dummy a b
40 ## stdout: ['a', 'b']
41
42 #### args that look like flags are passed after script
43 script=$TMP/sh1.sh
44 echo 'argv.py "$@"' > $script
45 chmod +x $script
46 $SH $script --help --help -h
47 ## stdout: ['--help', '--help', '-h']
48
49 #### args that look like flags are passed after -c
50 $SH -c 'argv.py "$@"' --help --help -h
51 ## stdout: ['--help', '-h']
52
53 #### exit with explicit arg
54 exit 42
55 ## status: 42
56
57 #### exit with no args
58 false
59 exit
60 ## status: 1
61
62 #### --rcfile in non-interactive shell prints warnings
63 echo 'echo rc' > rc
64
65 $SH --rcfile rc -i </dev/null 2>interactive.txt
66 grep -q 'warning' interactive.txt
67 echo warned=$? >&2
68
69 $SH --rcfile rc </dev/null 2>non-interactive.txt
70 grep -q 'warning' non-interactive.txt
71 echo warned=$? >&2
72
73 head *interactive.txt
74
75 ## STDERR:
76 warned=1
77 warned=0
78 ## END
79 ## N-I bash/dash/mksh/zsh STDERR:
80 warned=1
81 warned=1
82 ## END
83
84 #### accepts -l flag
85 $SH -l -c 'exit 0'
86 ## status: 0
87
88
89 #### accepts --login flag (dash and mksh don't accept long flags)
90 $SH --login -c 'exit 0'
91 ## status: 0
92 ## OK dash status: 2
93 ## OK mksh status: 1
94