Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!watmath!clyde!ima!haddock!karl
From: karl@haddock.UUCP
Newsgroups: comp.bugs.4bsd,comp.unix.questions
Subject: $* and $@ (Was: nohup (from Bourne shell))
Message-ID: <197@haddock.UUCP>
Date: Fri, 12-Dec-86 20:36:41 EST
Article-I.D.: haddock.197
Posted: Fri Dec 12 20:36:41 1986
Date-Received: Mon, 15-Dec-86 20:32:40 EST
References: <181@haddock.UUCP> <106@quacky.UUCP>
Reply-To: karl@haddock.ISC.COM.UUCP (Karl Heuer)
Followup-To: comp.unix.questions
Distribution: world
Organization: Interactive Systems, Boston
Lines: 45
Xref: watmath comp.bugs.4bsd:79 comp.unix.questions:325

Newsgroups: comp.bugs.4bsd,comp.unix.questions
Subject: $* and $@ (Was: nohup (from Bourne shell))
References: <181@haddock.UUCP> <106@quacky.UUCP>
Reply-To: karl@haddock.ISC.COM.UUCP (Karl Heuer)
Followup-To: comp.unix.questions
Distribution: world
Organization: Interactive Systems, Boston

In article <106@quacky.UUCP> dce@quacky.UUCP (David Elliott) writes:
>In article <181@haddock.UUCP> karl@haddock.isc.com.UUCP (Karl Heuer) writes:
>>The shell script /usr/bin/nohup uses `$*' where it should use `$@'; this
>>breaks things like `nohup sh -c "echo foo"' because the quotes get lost.
>
>Yes and no. Nohup should say   exec nice -5 "$@"

That's what I meant, of course.  Thanks for the clarification.

>There is one slight problem with "$@" [namely, when $# = 0 it gives you a
>null string instead of nothing at all].  I've discussed this bug with
>Steve Bourne, and he agrees that it is incorrect behavior.

Good!  I've been trying for years to convince people that it's a bug.

>Add [code elided] to the beginning of the subroutine macro() in macro.c, and
>the bug goes away. It is somewhat kludgy, but it works.

The whole concept of "$@" is somewhat kludgy.  (Why doesn't "a$@b" return
"a$1b" "a$2b" ... ?)  But it's indispensible.

>Also, while I'm here, I'll show a way to properly build a list into a single
>variable. Typically, this is done as
>	for i { List="$List $i"; }
>	command $List
>This is incorrect, since it breaks if an argument contains spaces or tabs
>or newlines or what have you. The following works much better:
>	for arg { Arg_list="$Arg_list '$arg'"; }
>	eval command "$Arg_list"

Better, but now it breaks if an argument contains a single quote.  Is there a
method that preserves all the printing characters, and works on all versions
of sh?  (I tried to do something with   sed 's/[\\"`$]/\\&/'  and stuffing the
result into double quotes, but I couldn't find a portable mechanism.)

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
(Followups to comp.unix.questions, unless you have more bugs to report.)