Is this a bug in sh?

GP Saxena gp at ist.CO.UK
Fri Jul 7 03:40:39 AEST 1989


In article <PAUL.89Jul4155856 at marvin.moncam.co.uk>, paul at 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.



More information about the Comp.unix.questions mailing list