cron job verification

Bill Sconce sconce at in-spec-inc.com
Wed Feb 2 20:42:00 EST 2005


On Wed, 2 Feb 2005 18:19:48 -0500
Ed Robitaille <erobitaille at eagle1st.com> wrote:

> On Wed, 2 Feb 2005 10:45:31 -0500
> Bob Bell <bbell at macroped.com> wrote:
> 
> > On Wed, Jan 12, 2005 at 12:15:46AM -0500, Derek Martin wrote:
> > >   #!/bin/sh
> > >   # NEVER start shell scripts as #!/bin/bash -- it can lead to strange
> > >   # and unintended results.
> > 
> > Like what?  I've never had a problem.  If I specifically am using bash
> > features, I always say "/bin/bash", as "/bin/sh" could mean Bourne shell
> > or POSIX shell.

> If I'm not mistaken, If #!/bin/sh is used the shell will use what is set for
> the user variable $SHELL when a user logs in. I use zsh and have SHELl set 
> for /bin/zsh.


A little more information on just the shebang ("!#") part of things.

When an executable file is invoked it's the kernel which figures out how
to run it.  If the magic "!#" line appears at the front of the file the
kernel passes the file to whatever the magic "!#" line points to (in the
case under discussion, to /bin/sh).  The SHELL environment varible isn't 
involved.  Indeed, no shell is involved at all.  (Not in interpreting the 
shebang - in the case under discussion a shell is _pointed to_ by the 
shebang, though, which is potentially confusing.)

Aside: the usual "scripting" case doesn't present the shell confusion:

#!/usr/bin/python
print 'Hello World'

..which causes the contents of the file following the shebang line to be
executed by the handler specified by the shebang line.  See?  No shell.

I believe the SHELL environment variable is primarily there to tell you
(or your scripts) what shell you (or they) are running under.  Someone
may correct me on that.

HTH
-Bill

P.S.  As for the shell you get when you log in, it's specified in
/etc/passwd.

P.P.S.  On many systems if you do an "ls -l /bin/sh" you'll find that
this isn't an actual executable but a symbolic link.  On my (Debian)
systems it's a symbolic link which points to   ...surprise, bash:

$ ls -l /bin/sh
lrwxrwxrwx    1 root     root            4 May 10  2003 /bin/sh -> bash
$




More information about the gnhlug-discuss mailing list