[Bug 252061] sh does not pass $@ parameters properly
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Wed Dec 23 01:48:03 UTC 2020
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=252061
Bug ID: 252061
Summary: sh does not pass $@ parameters properly
Product: Base System
Version: 11.4-RELEASE
Hardware: Any
OS: Any
Status: New
Severity: Affects Some People
Priority: ---
Component: bin
Assignee: bugs at FreeBSD.org
Reporter: jguojun at gmail.com
When using $@ to pass parameter, sh supposed to pass every tuple as is.
That is, passing "abc 123" to another sh script, "abc 123" should be intact as
one parameter.
Currently, using $@ and $* to pass parameter from one sh script to another does
not make difference: all parameters are passed as single items.
A simple testing script is appended below and save it to two files -- sh1 and
sh2.
run sh1 with parameters "123 456" "abc def" xyz.
The orignal parameter tuples are 3 shown in sh1 correctly.
According to maunal, $@ should pass "123 456" "abc def" xyz as is (3 tuples).
$* should pass "123 456" "abc def" xyz as 5 items as 123 456 abc def xyz
However, both $@ and $* pass 5 parameters to the sh2.
: ./sh1 "123 456" "abc def" xyz
./sh1 3 tuples
123 456
abc def
xyz
./sh2 5 tuples
123
456
abc
def
xyz
./sh2 5 tuples
123
456
abc
def
xyz
: cat sh1
#!/bin/sh
echo
echo $0 $# tuples
n=1
while [ $n -le $# ]; do
eval echo \$$n
n=$((n+1))
done
[ $0 = sh1 -o $0 = ./sh1 ] && ./sh2 $@
[ $0 = sh1 -o $0 = ./sh1 ] && ./sh2 $*
--
You are receiving this mail because:
You are the assignee for the bug.
More information about the freebsd-bugs
mailing list