shell magic number with a -

In one of our internal scripts (unix.run), I have noticed that the following shebang.

#!/bin/sh -
for i in test1 test2 test3 ; do
.
.
.

Any idea what the - in the magic number stands for ?

And what impact does it have on the script ?

Continuing on the same script, I have the following for unix.run

ls -l unix.run
-rw-------    1 XXXXXX g900          187 Jul  8 04:29 unix.run

If I do a

./unix.run

it says 'Permission denied'

But if I run it as,

sh unix.run

it works well.

Why the difference in behaviour between ./unix.run and sh unix.run?

Shouldn't it always say 'Permision denied' in both the cases ?

Any inputs/pointers on these two points, highly appreciated.

Thanks,
Vino

To answer the first question, this is to disable the option processing by sh. This means that if you pass any arguments to the script, sh will not try to interpret them itself, but will treat them as arguments.

To quote the BSD sh manual,

In the case of your second question, the script does not run as './unix.run' because you are trying to 'execute' a file that is not executable (no x bits are set). With 'sh ./unix.run' the binary '/usr/bin/sh' is executed and the unix.run script is passed to it as arguments.

Cheers!

P.S. BTW, the magic number only comprises the first 2 or 3 (both are legal) bytes in the file. The rest of the line tells the kernel what is to be used to interpret the rest of the file.

What os? HP-UX magic man page says:

struct magic_number { 
    unsigned short    system_id; 
    unsigned short    file_type; 
}; 
typedef      struct    magic_number MAGIC; 

Oops! Thats 3 or 4! Its there in the reply by Perderabo in the FAQs. :o

Thanks for pointing that out Perderabo.