bug in /bin/sh
John Worley
worley at ardent.UUCP
Fri May 26 10:00:48 AEST 1989
> There is a problem in the
> argument passing when shell functions are used: The expansion of $* turns
> quoted strings into multiple arguments. The expansion of $1, for example,
> works fine:
>
Not really. Parameters are substituted before the command is parsed, so
any white space in the parameter will be seen as separating the arguments,
unless the parameter is enclosed in "". The example
print() {
echo $1
}
when invoked with, is executed as follows:
print "a b" c -> echo $1
-> echo a b # Note - 2 params!
-> a b
visually indistinguishable from
print() {
echo "$1"
}
which is what you though was happening.
> But, if I type:
>
> $ mail() /usr/bin/mailx $*
> $ mail -s "a b c d e f" chris
This is defintely NOT a bug. From the manual page for the Bourne shell:
* If $* is within a pair of double quotes, the positional
* parameters are substituted and quoted, separated by quoted
* spaces ("$1 $2 ..."); however, if $@ is within a pair of
* double quotes, the positional parameters are substituted and
* quoted, separated by unquoted spaces ("$1" "$2" ... ).
So, /bin/sh is behaving as documented; what you wanted was:
mail() {
/usr/bin/mailx "$@"
}
Regards,
John Worley
uunet!ardent!worley
More information about the Comp.bugs.sys5
mailing list