shell magic number with a -


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell magic number with a -
# 1  
Old 07-08-2005
shell magic number with a -

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

Code:
#!/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

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

If I do a

Code:
./unix.run

it says 'Permission denied'

But if I run it as,

Code:
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
# 2  
Old 07-08-2005
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,
Quote:
Originally Posted by BSD sh manual
A ``--'' or plain ``-'' will stop option processing and will
force the remaining words on the command line to be treated as arguments.
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.

Last edited by blowtorch; 07-08-2005 at 11:47 AM.. Reason: an aside about the magic number
# 3  
Old 07-08-2005
Quote:
Originally Posted by blowtorch
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:
Code:
struct magic_number { 
    unsigned short    system_id; 
    unsigned short    file_type; 
}; 
typedef      struct    magic_number MAGIC;

# 4  
Old 07-09-2005
Quote:
Originally Posted by blowtorch
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.
Oops! Thats 3 or 4! Its there in the reply by Perderabo in the FAQs. Smilie

Thanks for pointing that out Perderabo.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Magic number error

hi . my " /usr " was full ,so i went into the failsafe mode in solaris 10 and used format utilily to adjust space for it and labeled it. But after that whenever i try to boot solaris normally ,it is giving "magic number error" I tried fsck -o b=32 /dev/dsk/c0d0s6 (for /usr) newfs -N... (6 Replies)
Discussion started by: tushardul
6 Replies

2. Solaris

Bad magic number error

So we have a new to us v240 server with no OS installed. It has an outdated version of OB and ALOM so before we install the OS we want to update both. We have a DVD with the latest OB patch burned on it. We do the boot cdrom command but receive the Bad Magic Number Error. Does an OS need to... (2 Replies)
Discussion started by: dunkpancakes
2 Replies

3. Solaris

Solaris 8.2 Bad magic number

I'll keep it fairly straight forward. I work with a Solaris server and magically today it decided to take a dump on me. At first it give a long list of files that couldn't be acessed before terminating the boot process and returning to the 'ok' prompt. Booting in single-user mode allowed me to run... (4 Replies)
Discussion started by: Aon
4 Replies

4. AIX

module has an invalid magic number

Hello everybody: I have a trouble running an application which connects to an Oracle server, I got this message: Dependent module /opt/oracle/product/10.2/lib/libclntsh.so could not be loaded. The module has an invalid magic number. Running ldd MyApp doesn't report missing symbols, I've... (1 Reply)
Discussion started by: edgarvm
1 Replies

5. UNIX for Dummies Questions & Answers

Solaris magic number problem

Hello, When I boot up my ancient SUNOS 5 system. it stops at the OK prompt and complains about a bad magic number. I have told that I need run fsck but I cannot seem to do so from the OK prompt. How can I get into a diagnostic mode so I can run fsck? Thanks, (1 Reply)
Discussion started by: mojoman
1 Replies

6. Solaris

BAD magic number in disc label...

Hello All, I m very new to this forum. i m having SUN NETRA X1 server with 40 GB HDD (Seagate) & 128 MB RAM. i m trying this server for SUN 10 Practise. As i m installing SUN 9 /10 with CD ,its giving me error after OK propmt *************************** #boot cdrom or #boot cdrom... (16 Replies)
Discussion started by: amrut_k
16 Replies

7. Solaris

wrong magic number

/pci@if,0/pci@1,1/ide@3/dad@0,0 corrupt label wrong magic number can u plz suggustion me (6 Replies)
Discussion started by: tirupathi
6 Replies

8. Filesystems, Disks and Memory

LVM magic number 0x4D48

LVM partition(8e type) begins with a magic number(0x4D48) - HM, At this sector, I get the name of volume group plus two three more structures, which I am unable to decipher. So, if anyone can let me know the details of these structures. In my case, I had made two logical volumes in my LVM... (2 Replies)
Discussion started by: ghimanshu
2 Replies

9. Filesystems, Disks and Memory

Bad Magic Number

Dear All, i have a SCSI hard disk drive i'm installing on it solaris 5 and the workstation is sun sparc, i made an image of this H.D using Norton Ghost 6, so i took off the SCSI H.D from the sun workstation and put it on a Compaq server then i booted the server from the Norton Ghost floppy disk... (0 Replies)
Discussion started by: wesweshahaha
0 Replies

10. UNIX for Advanced & Expert Users

bad magic number

Hi, when installing a piece of third part software I get the error "Bad magic number" at one point when it tries to use libraries from the bea tuxedo server. Am I correct that this means that the software is expecting 32bit while I'm on 64bit? Is there a way around it or can it only be solved... (5 Replies)
Discussion started by: rein
5 Replies
Login or Register to Ask a Question