Path: utzoo!attcan!uunet!ncrlnk!ncrcae!ece-csc!ncsuvx!gatech!emcard!ncrats!iccdev!steve From: steve@iccdev.UUCP (Steve Clamage) Newsgroups: comp.unix.questions Subject: Re: Bourne Shell Comments Problem Summary: exec, not csh Keywords: Shells exec #! Message-ID: <369@iccdev.UUCP> Date: 29 Sep 88 16:31:40 GMT References: <292@dsacng1.UUCP> <375@stiatl.UUCP> <8567@smoke.ARPA> <1628@ficc.uu.net> Reply-To: steve@iccdev.UUCP (Steve Clamage) Organization: Industrial Computer Corp., Atlanta Lines: 40 In article <1628@ficc.uu.net> peter@ficc.uu.net (Peter da Silva) writes: [Discussion of #! at the beginning of shell scripts deleted] > >You must not have used systems with the csh available then, since csh (not >sh) uses the first character to determine whether to pass the script off onto >the bourne shell. Some might ask whether this is broken, since after all anyone >writing csh scripts has to be off their nut, but it is a fact of life. If you >have csh, check your bourne shell scripts to make sure they're csh proof. >Peter da Silva `-_-' Ferranti International Controls Corporation. >"Have you hugged U your wolf today?" peter@ficc.uu.net Actually, the #! at the beginning of a file is not a feature of csh, it is a feature of exec()! Do a 'man exec' and you'll find out that it looks at the first two bytes of the exec'ed file, and if it finds them, uses the next word as the name of the interpreter for that file. Try something like this and you'll see what I mean: #include main() { char *argv[]; argv[0]=NULL; execv("foo",argv); } Where "foo" is just: #!/bin/ls -l (Don't forget to chmod +x foo..) I was pretty surprised when I first found out about this, but it does make sense in a twisted sort of UNIX-y way. ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ Steve Clamage - Industrial Computer Corp., Atlanta, GA UUCP: ...gatech!ncrats!iccdev!steve "But then on the other hand I might/Keep the wax/And melt it down.." DISCLAIMER: Disclaimer? I don't even know 'er! ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~