Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!eru!luth!sunic!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: Another sed question. Message-ID: <4694@pinas.cs.vu.nl> Date: 1 Dec 89 23:15:12 GMT References: <37091@ames.arc.nasa.gov> Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Informatica, Amsterdam Lines: 61 In article <37091@ames.arc.nasa.gov> gahooten@orion.arc.nasa.gov (Gregory A. Hooten) writes: \I ran across a shell script that had this as the first line of code. \ \------------------------------------------------------------- \#!/bin/sed d1 Probably: #!/bin/sed 1d When you try to execute this script, the kernel opens it to find out what kind of executable it is. The header of a *binary* includes the size of the text, data and bss segments etc.. This file, however, isn't a binary: it's an EXECUTABLE shell script. The kernel discovers the `#!' MAGIC NUMBER and takes the following word as the real executable to start. There may be 1 option specified. Suppose the file is called `foo', then $ foo is handled as if you had typed $ /bin/sed 1d foo (See execl(3).) As you noticed this command will delete the first line of `foo' and print the rest of the script. So the script is equivalent to: #!/bin/sh cat << \EOF EOF The difference: the first form is faster, because there's no invocation of /bin/sh. (In the second form there's no need to use sed instead of cat.) Here's another nice example (put it in your bin directory): ----------8<----------8<----------8<----------8<----------8<---------- #!/bin/sed 1d C operator precedence/associativity chart Arity Operator Assoc -------------------------------------------------------------- mixed () [] -> . l -> r unary ! ~ ++ -- - (type) * & sizeof r -> l binary * / % l -> r binary + - l -> r binary << >> l -> r binary < <= > >= l -> r binary == != l -> r binary & l -> r binary ^ l -> r binary | l -> r binary && l -> r binary || l -> r ternary ?: r -> l binary = += -= *= /= %= >>= <<= &= ^= |= r -> l binary , l -> r -------------------------------------------------------------- -- `Take John Berryhill: the guy is everywhere! All because one day he typed "rn" instead of [rm]' (Richard Sexton) | maart@cs.vu.nl, uunet!mcsun!botter!maart