Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!uunet!mcvax!ukc!etive!hwcs!zen!frank From: frank@zen.co.uk (Frank Wales) Newsgroups: comp.unix.questions Subject: Re: Is this a bug in sh? Message-ID: <1634@zen.co.uk> Date: 5 Jul 89 14:11:48 GMT References: Reply-To: frank@zen.co.uk (Frank Wales) Organization: Zengrange Limited, Leeds, England Lines: 55 [I tried mailing, but it bounced.] In article paul@moncam.co.uk write: >Consider the two (executable) shell scripts.. > >script1 is and script2 is > >echo $0 echo $0 >name=`basename $0` name= `basename $0` > ^ > Note the space here. > >executing script1 prints "script1" as you would expect. Executing >script2 prints "script2" "script2" ...... and spawns shells at an >enormous rate. Valid shell construct number one; Assignments to shell variables (a.k.a. keyword parameters) have the syntax: = note...no spaces following the '='. If is missing, then is set to the null string. Valid shell construct number two: Execution of a command with a shell variable set to a particular value *in the environment of that command only*: = If is missing, is set to the null string while is executed. can be any shell expression which results in a non-null string for subsequent execution. Hence, in the example you give, the line: name= `basename $0` sets name to the null string, evaluates the backquoted expression (which results in the basename of the script), then executes the script itself with name set to null. This leads to unending recursion of the script which contains it. Today's complex technical question: based on this, decide what you think the command line: binglebongle=Fred echo $binglebongle will print, then try it and see what happens. At this point, read the manual. :-) -- Frank Wales, Systems Manager, [frank@zen.co.uk<->mcvax!zen.co.uk!frank] Zengrange Ltd., Greenfield Rd., Leeds, ENGLAND, LS9 8DB. (+44) 532 489048 x217