freebsd-dev/bin/sh/tests/parameters/positional8.0
Jilles Tjoelker a5cb58abc8 sh: Fix ""$@, which should not use the special case for "$@".
"$@" should expand to no words if there are no positional parameters, but
""$@ should always expand to at least an empty word.
2015-11-18 21:09:03 +00:00

32 lines
618 B
Plaintext

# $FreeBSD$
failures=''
ok=''
testcase() {
code="$1"
expected="$2"
oIFS="$IFS"
eval "$code"
IFS='|'
result="$#|$*"
IFS="$oIFS"
if [ "x$result" = "x$expected" ]; then
ok=x$ok
else
failures=x$failures
echo "For $code, expected $expected actual $result"
fi
}
testcase 'shift $#; set -- ""$*' '1|'
testcase 'shift $#; set -- $*""' '1|'
testcase 'shift $#; set -- ""$@' '1|'
testcase 'shift $#; set -- $@""' '1|'
testcase 'shift $#; set -- """$*"' '1|'
testcase 'shift $#; set -- "$*"""' '1|'
testcase 'shift $#; set -- """$@"' '1|'
testcase 'shift $#; set -- "$@"""' '1|'
test "x$failures" = x