1 | #! /bin/sh
|
2 |
|
3 | # From https://github.com/oilshell/oil/issues/1449
|
4 |
|
5 | set -e
|
6 |
|
7 | nargs () {
|
8 | n_args=$#
|
9 | return 0
|
10 | }
|
11 |
|
12 | check () {
|
13 | if [ "$1" = "$2" ]; then
|
14 | printf 'ok: %s\n' "$3"
|
15 | else
|
16 | printf 'FAIL: %s: got "%s" expected "%s"\n' "$3" "$1" "$2"
|
17 | status=1
|
18 | fi
|
19 | }
|
20 |
|
21 | a="a b"
|
22 |
|
23 | nargs $a
|
24 | check $n_args 2 'nargs $a'
|
25 |
|
26 | nargs "$a"
|
27 | check $n_args 1 'nargs "$a"'
|
28 |
|
29 | nargs "$a" $a
|
30 | check $n_args 3 'nargs "$a" $a'
|
31 |
|
32 | n_args=`nargs "$a"; echo $n_args`
|
33 | check $n_args 1 '`nargs "$a"`'
|
34 |
|
35 | n_args=`nargs "$a" $a; echo $n_args`
|
36 | check $n_args 3 '`nargs "$a" $a`'
|
37 |
|
38 | eval "nargs \"$a\""
|
39 | check $n_args 1 'eval "nargs \"$a\""'
|
40 |
|
41 | eval "nargs \"$a\" $a"
|
42 | check $n_args 3 'eval "nargs \"$a\" $a"'
|
43 |
|
44 | n_args=`eval "nargs \"$a\""; echo $n_args`
|
45 | check $n_args 1 'eval "nargs \"$a\""'
|
46 |
|
47 | n_args=`eval "nargs \"$a\" $a"; echo $n_args`
|
48 | check $n_args 3 'eval "nargs \"$a\" $a"'
|
49 |
|
50 | exit $status
|