Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!ukc!icdoc!ist!gp From: gp@ist.CO.UK (GP Saxena) Newsgroups: comp.unix.questions Subject: Re: Is this a bug in sh? Summary: Re: Is this a bug in sh? NO it is not! Message-ID: <2301@istop.ist.CO.UK> Date: 6 Jul 89 17:40:39 GMT References: Distribution: all Organization: Imperial Software Technology, London, UK Lines: 36 In article , paul@moncam.co.uk (Paul Hudson) writes: > 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 because in script2, the shell treats the line name= `basename $0` as two separate actions viz., 1. the parameter "name" is set to null. 2. the "simple command" (RTFM :-) ) `basename $0` is executed. What happens in your case is that script2 gets executed within script2 as a result of (2) above, and this happens recursively. BTW, this will happen only if script2 is an executable shell script! > This is sunos4.0 on a sun3/50. > > Go on, tell me I haven't RTFM .... ;-) Then tell me why it's this way. > I tried this on other BSD systems, where too the same thing happens. I do not think its a bug though its a bit disconcerting when such a thing happens. gp saxena Disclaimer: I do not make any claims.