Old-timer UN*X trivia [was Re: Error confusing a newbie]

Donn Cave donn at u.washington.edu
Mon Dec 13 12:41:32 EST 1999


Quoth grant at nowhere. (Grant Edwards):
| In article <slrn859sub.bj2.mgm at unpkhswm04.bscc.bls.com>, Mitchell Morris wrote:
|>>In Linux, it runs with a shell! It seems Linux defaults to
|>>/bin/sh if an executable text file is executed even without a
|>>#! as the "magic" number. I'm not sure if this is a bug or a
|>>feature...
|
| That's the way all of the Unix systems I've used for the past
| 15 years have worked.  If a file is executble, and doesn't have
| a magic number, then it is assumed to be a /bin/sh script.

Yes, usually, but it's not UNIX per se, it's up to the application
that actually tries to execute the file.  First thing is usually an
execve(2), and at this point the UNIX magic number either works or
doesn't.  If it doesn't, execve() returns an error and the application
decides what to do.  Some, probably all, Bourne shells try to interpret
the script themselves.  The C Shell looks for a lone "#" at the top
and uses that to decide whether to try to interpret the script, or
run the Bourne shell on it.  I think "rc" just reports an error.

| >As a completely off-topic aside, when did the magic number
| >cease being "#! /" and turn into just "#!"?
|
| You'd have to look at the sources for the exec system call, but
| I've always understood that magic numbers were traditionally 16
| bit values.

Right.

	Donn Cave, University Computing Services, University of Washington
	donn at u.washington.edu



More information about the Python-list mailing list