[ale] why bash when ksh is default?

Jeff Barber jeffb at sware.com
Mon Mar 18 11:55:57 EST 1996


Unix Guru Dude writes:
> }On the SVR4 I'm using, /sbin/sh is executed for such a script, according
> }to the output of truss:  
> }
> }
> }$ echo $SHELL
> }/usr/bin/bash
> }
> }$ cat test.sh
> }echo THIS is a test script $0
> 
> I believe this is a function of you login shell, /usr/bin/bash.  Humor me,
> try this:
> 
> exec ksh			# full path mind you
> export SHELL=ksh	# ditto
> echo '[[ -x $0 ]] && date' > test.sh
> chmod 700 test.sh
> ./test.sh
> 
> If it runs via /bin/sh, it will fail to recognize the '[[' construct.
> My expectation is that since SHELL is set to ksh, the shell will be run
> with ksh...

Actually, what's happening here is that, if the exec fails, ksh tries to
interpret the file itself without regard to the setting of SHELL.  Try
this with the same test.sh you prepared above:

  exec csh
  ./test.sh

You'll also find that /bin/sh gets executed, regardless of the setting of
your SHELL variable.  [Though on my Linux system, /bin/sh is actually a
symlink to bash anyway, so it won't fail to recognize the '[[' construct
anyway.]


> }$ truss -o /tmp/test.sh.truss test.sh
> 
> truss?   New to me...........

And you call yourself "Unix Guru Dude"?  ;-)  (You should find truss on
a SVR4 system, at least -- it's quite handy at times.)


-- Jeff






More information about the Ale mailing list