OILS / spec / sh-usage.test.sh View on Github | oilshell.org

94 lines, 32 significant
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
24echo -n '' | $SH
25## stdout-json: ""
26## status: 0
27
28#### shell obeys --help (regression for OSH)
29n=$($SH --help | wc -l)
30if test $n -gt 0; then
31 echo yes
32fi
33## STDOUT:
34yes
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
43script=$TMP/sh1.sh
44echo 'argv.py "$@"' > $script
45chmod +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
54exit 42
55## status: 42
56
57#### exit with no args
58false
59exit
60## status: 1
61
62#### --rcfile in non-interactive shell prints warnings
63echo 'echo rc' > rc
64
65$SH --rcfile rc -i </dev/null 2>interactive.txt
66grep -q 'warning' interactive.txt
67echo warned=$? >&2
68
69$SH --rcfile rc </dev/null 2>non-interactive.txt
70grep -q 'warning' non-interactive.txt
71echo warned=$? >&2
72
73head *interactive.txt
74
75## STDERR:
76warned=1
77warned=0
78## END
79## N-I bash/dash/mksh/zsh STDERR:
80warned=1
81warned=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