Bourne Shell Comments Problem
Steve Clamage
steve at iccdev.UUCP
Fri Sep 30 02:31:40 AEST 1988
In article <1628 at ficc.uu.net> peter at 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 at 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 <stdio.h>
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!
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
More information about the Comp.unix.questions
mailing list