1 #!/bin/bash
2 #
3 # Usage:
4 # ./sh-usage.test.sh <function name>
5
6 #### sh -c
7 $SH -c 'echo hi'
8 ## stdout: hi
9 ## status: 0
10
11 #### empty -c input
12 # had a bug here
13 $SH -c ''
14 ## stdout-json: ""
15 ## status: 0
16
17 #### empty stdin
18 # had a bug here
19 echo -n '' | $SH
20 ## stdout-json: ""
21 ## status: 0
22
23 #### shell obeys --help (regression for OSH)
24 n=$($SH --help | wc -l)
25 if test $n -gt 0; then
26 echo yes
27 fi
28 ## STDOUT:
29 yes
30 ## END
31 ## N-I dash/mksh stdout-json: ""
32
33 #### args are passed
34 $SH -c 'argv.py "$@"' dummy a b
35 ## stdout: ['a', 'b']
36
37 #### args that look like flags are passed after script
38 script=$TMP/sh1.sh
39 echo 'argv.py "$@"' > $script
40 chmod +x $script
41 $SH $script --help --help -h
42 ## stdout: ['--help', '--help', '-h']
43
44 #### args that look like flags are passed after -c
45 $SH -c 'argv.py "$@"' --help --help -h
46 ## stdout: ['--help', '-h']
47
48 #### exit with explicit arg
49 exit 42
50 ## status: 42
51
52 #### exit with no args
53 false
54 exit
55 ## status: 1
56