Article View: comp.bugs.4bsd
Article #482$* and $@ (Was: nohup (from Bourne shell))
From: karl
Date: Sat, 13 Dec 1986 01:36
Date: Sat, 13 Dec 1986 01:36
45 lines
2722 bytes
2722 bytes
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.)
Technical Details
Message-ID:
<197@haddock.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!ima!haddock!karlReferences:
<181@haddock.UUCP> <106@quacky.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!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