Re: Script Header
From: Alexander Mueller (postmaster_at_127.0.0.1)
Date: 12/28/04
- Next message: Kenny McCormack: "Re: schedule a script in crontab file problem"
- Previous message: Chris F.A. Johnson: "Re: How do I detect which shell (ksh, bash, csh, zsh, tcsh) is currently used?"
- In reply to: Bruce Barnett: "Re: Script Header"
- Next in thread: Kenny McCormack: "Re: Script Header"
- Reply: Kenny McCormack: "Re: Script Header"
- Reply: Janis Papanagnou: "Re: Script Header"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 28 Dec 2004 19:14:47 GMT
Bruce Barnett wrote:
>
> Yes.
> do a
> od -b executable | head
>
> On a shell script, I get
>
> 0000000 043 041 ..............
>
> The first number is the byte count, and the next two are octal values.
>
>
> while on an executable, I get
>
> 0000000 177 105
>
> On old Unix systems (not on this Linux system), there was a man page on
> a.out that described the binary formats.
> The proper binary code depends on the hardware.
>
>
> You can TRY to execute a garbage file.
> The OS will complain
>
> filename: Exec format error. Binary file not executable.
>
> It's a little tricker when you deal with a data file. A *.txt file
> isn't executable. The OS has to know what program is used to process
> this file. Mac, Unix and WIndows have different mechanisms. So when
> you tell it to process a text file, it has to figure out how to do
> this. This is when extensions are useful. Unix also has the "file"
> command to try to guess the file type. But this can be fooled.
Thanks Bruce. According to this, I would assume the execution process
works in the following way.
- The user attempts to execute a file
- The shell will check whether this file has the executable flag set,
if not it will fail
- Otherwise it will pass the name to the exec() function
- Now the system tries to determine whether the file is a script or a
binary exectuable, based upon the first two bytes "magic code"
- If these "magic code" consists of the two ascii values 35 and 33
("#!") it is reconised as script and the exec() function tries to
determine the target interpreter by parsing the first line
- Otherwise, if the "magic code" represents a (support) binary
executable, the file itself will be executed by the particular loader.
So far I would have understood it. Although I have to admit that I do
not consider this solution as a rather dirty workaround for a sole
script convenience, but this is another story.
However what makes me wonder is, if I change the script header to
something different (eg: "@!/bin/bash"), I will get an error message
telling me that my CURRENT shell cant execute this file. But where does
my current shell suddenly come in? Who tells it to actually execute this
file? Is the shell actually already parsing the file before it hands it
off to exec() or is exec() doing a callback to the current shell upon an
unknown "magic code"?
I am aware that this might be already a bit off topic for a shell group,
but I dont know which other group would be most appropriate. So please
do a follow-up if necessary.
Thanks again,
Alexander
- Next message: Kenny McCormack: "Re: schedule a script in crontab file problem"
- Previous message: Chris F.A. Johnson: "Re: How do I detect which shell (ksh, bash, csh, zsh, tcsh) is currently used?"
- In reply to: Bruce Barnett: "Re: Script Header"
- Next in thread: Kenny McCormack: "Re: Script Header"
- Reply: Kenny McCormack: "Re: Script Header"
- Reply: Janis Papanagnou: "Re: Script Header"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|