The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bad magic number on /dev/md0 ravinandan UNIX for Advanced & Expert Users 0 08-17-2007 07:56 AM
LVM magic number 0x4D48 ghimanshu Filesystems, Disks and Memory 2 07-18-2007 08:27 AM
Bad Magic Number wesweshahaha Filesystems, Disks and Memory 0 05-18-2006 01:28 PM
Bad magic number batosai SUN Solaris 1 04-22-2006 11:29 AM
bad magic number rein UNIX for Advanced & Expert Users 5 01-05-2005 11:27 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 07-08-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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 (permalink)  
Old 07-08-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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 10:47 AM.. Reason: an aside about the magic number
  #3 (permalink)  
Old 07-08-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,100
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 (permalink)  
Old 07-08-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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.

Thanks for pointing that out Perderabo.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0