bug in /bin/sh

Billy G. Allie bga at bgalli.eds.com
Fri May 26 14:05:57 AEST 1989


In article <883 at cetia4.UUCP>, chris at cetia4.UUCP (Christian Bertin) writes:
> First, I apologized if this is an ancient bug. There is a problem in the
> argument passing when shell functions are used: The expansion of $* turns
> quoted strings into multiple arguments.
>
> But, if I type:
> 
> 			$ mail() /usr/bin/mailx $*
> 			$ mail -s "a b c d e f" chris
> 
> the quoted string has become multiple arguments to 'mailx'

The shell expand the parameters $* and $@ into a list of all positional 
parameters seperated by spaces so that the following command is executed:

	/usr/bin/mailx -s a b c d e f chris

To get the effect you desire, you must use the $@ parameter within quotes.
For example, your mail function should be written as follows:

	mail() /usr/bin/mailx "$@"

Note that both the $* and the $@ parameters receive special treatment by
the shell when they are quoted.  "$*" is equivalent to "$1 $2 $3 ..." and
"$@" is equivalent to "$1" "$2" "$3" ....
-- 
____	   | Billy G. Allie	| Internet..: bga at bgalli.eds.com
|  /|	   | 7436 Hartwell	| UUCP......: uunet!{mcf|edsews}!bgalli!bga
|-/-|----- | Dearborn, MI 48126	| Compuserve: 76337,2061
|/  |LLIE  | (313) 582-1540	| Genie.....: BGALLIE



More information about the Comp.bugs.sys5 mailing list