Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: $Revision: 1.6.2.16 $; site ISM780B.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!yale!ISM780B!geoff From: geoff@ISM780B.UUCP Newsgroups: net.unix-wizards Subject: Re: magic numbers? (teach me, please) Message-ID: <28500056@ISM780B.UUCP> Date: Wed, 27-Nov-85 12:55:00 EST Article-I.D.: ISM780B.28500056 Posted: Wed Nov 27 12:55:00 1985 Date-Received: Sat, 30-Nov-85 00:30:10 EST References: <124@rexago1.UUCP> Lines: 33 Nf-ID: #R:rexago1:-12400:ISM780B:28500056:000:1860 Nf-From: ISM780B!geoff Nov 27 12:55:00 1985 > Two questions. I presume they are related. > 1) How does the shell (exec?) know whether the command I just typed > is a shell script or one of several possible types of executable? Magic numbers are indeed the answer, if file mode allows execution, the first few bytes are read, (probably sizeof (struct filehdr)), and if they contain a recognized magic number, they are exec'd appropriately, else, a shell script is assumed. One drawback of this approach is that if an executable has an unknown magic number (say you got it off a different system), the shell will try to interpret it as a script, causing various syntax errors (the most common is "unexpected `('" ). > 2) Presuming the answer to #1 above has something to do with > magic numbers, who issues them? is there a common (definitive) > base of them or does each manufacturer/environment make up their > own set? On Sys5 (at least), there is an ascii file called /etc/magic, which contains magic numbers and information on what they mean, (the `file' command uses this). I _think_ the numbers are made up by the implementors of the particular a.out, but are standardized as much as possible by enlightened self-interest. (And by AT&T, one would have to be crazy not to use whatever they use to describe, say, a 5.0 binary). For further info, see file(1), /etc/magic (on any sys5), the UNIX* System 5 Support Tools Guide (various sections), all the shell documentation, and don't assume this is a complete list of references. Hope this helps. Geoffrey Kimbrough INTERACTIVE Systems Corporation, Santa Monica California. {decvax!vortex || ihnp4!allegra!ima}!ism780!geoff Don't hold your nose up so high, it blocks the light. Standard Disclaimers apply. * UNIX is a trademark of AT&T. * Shell is a trademark of Shell Oil Company. (8^)