Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!uunet!zephyr!tektronix!tekcrl!terryl From: terryl@tekcrl.LABS.TEK.COM Newsgroups: comp.unix.questions Subject: Re: Is this a bug in sh? Message-ID: <4248@tekcrl.LABS.TEK.COM> Date: 5 Jul 89 18:18:27 GMT References: Reply-To: terryl@tekcrl.LABS.TEK.COM Organization: Tektronix, Inc., Beaverton, OR. Lines: 46 Distribution: In article paul@moncam.co.uk (Paul Hudson) writes: > >Am I just showing my ignorance of sh? >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. > >This is sunos4.0 on a sun3/50. > >Go on, tell me I haven't RTFM .... ;-) Then tell me why it's this way. HOK, I'll tell ya "You haven't RTFM", but unfortunately, for this example you have to read between the lines in TFM. What is happening in script2 is you are assigning a null string to the variable name (by virtue of what you noted "Note the space here."); in sh it is possible to have a command line of the form: = What this does is to put whatever is into the environment variables, but only for the execution of . So in your example above, in script2 you are assigning the null string to the variable name, and then putting the variable name into the environment temporarily for the running of the command `basename $0` (which is script2, in your case). That's why script2 keeps printing out "script2" "script2" and spawns shells at an enormous rate....... Help Stamp Out Fascist News Software !!!! !!!!