Is this a bug in sh?
Pete French
pcf at galadriel.UUCP
Thu Jul 6 22:44:16 AEST 1989
>From article <PAUL.89Jul4155856 at marvin.moncam.co.uk>, by paul at moncam.co.uk (Paul Hudson):
>
> 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.
This took some playing to figure out but....
Try this :
$ name=abc date
Thu Jul 6 13:36:38 WET DST 1989
$ echo $name
abc
The shell will do the assignment and then run the next command on the line
for some unexplained reason. What you have is
name= `basename $0`
Which will be expanded (correctly) to
name= script2
The shell will now assign a blank to name and run script2 - thus re-running
the same script. This is what is causing the multiple shells.
Why the shell executes a command on the same line as an assignment is beyond
me, however. You normally need semicolons to separate commands on the same
line in shell. It sems to be acting as if it was...
$ name=abc; date
-Pete French.
More information about the Comp.unix.questions
mailing list