Re: Executable shell scripts

From: Mark Rosenstand
Date: Sat May 13 2006 - 07:18:40 EST


Arjan van de Ven <arjan@xxxxxxxxxxxxx> wrote:
> On Sat, 2006-05-13 at 13:03 +0200, Mark Rosenstand wrote:
> > Arjan van de Ven <arjan@xxxxxxxxxxxxx> wrote:
> > > On Sat, 2006-05-13 at 12:38 +0200, Mark Rosenstand wrote:
> > > > Hi,
> > > >
> > > > Is it in any (reasonable) way possible to make Linux support executable
> > > > shell scripts? Perhaps through binfmt_misc?
> > >
> > > ehhhhhh this is already supposed to work.
> >
> > It doesn't:
> >
> > bash-3.00$ cat << EOF > test
> > > #!/bin/sh
> > > echo "yay, I'm executing!"
> > > EOF
> > bash-3.00$ chmod 111 test
> > bash-3.00$ ./test
> > /bin/sh: ./test: Permission denied
>
> is your script readable as well? 111 is just weird/odd.

No, it's executable. This is what makes executable shell scripts
distinct from feeding the file to an interpreter.

>From http://www.faqs.org/faqs/unix-faq/faq/part4/section-7.html:

The script is called `executable' because just like a real
(binary) executable it starts with a so-called `magic number'
indicating the type of the executable. In our case this number is
`#!' and the OS takes the rest of the first line as the
interpreter for the script, possibly followed by 1 initial option
like:

#!/bin/sed -f

Suppose this script is called `foo' and is found in /bin,
then if you type:

foo arg1 arg2 arg3

the OS will rearrange things as though you had typed:

/bin/sed -f /bin/foo arg1 arg2 arg3

There is one difference though: if the setuid permission bit for
`foo' is set, it will be honored in the first form of the
command; if you really type the second form, the OS will honor
the permission bits of /bin/sed, which is not setuid, of course.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/