![]() | http://people.csail.mit.edu/jaffer/Docupage/sharpbang.html | |||||
#! (sharp-bang) | ||||||
|
cc 'sharpbang.c' -o '/usr/local/bin/#!'
On Unix systems, a Shell-Script is a file (with execute
permissions) whose first two characters are `#!'. The
interpreter argument must be the valid pathname to an
executable program. The directories named by environment variable
PATH
are not searched to find
interpreter. (If the file interpreter does not
exist or is not executable, then the Unix flags an error.)
If the file interpreter is a binary executable, then the operating system invokes interpreter with a single argument encapsulating the rest of the first line's contents (if not just whitespace), the pathname of the script file, and then any arguments which the shell-script was invoked with.
If the file interpreter is not a binary
executable, then it is ignored and the contents of script
file are piped (stdin
) to
/bin/sh
.
Unix scripts suffer from several drawbacks:
/bin/sh
.
The distinction between binary and non-binary interpreters was a bad idea originally, and remains so. Whether a file can be executed as a `#!' script depends on whether or not the referenced interpreter is a binary file.
If a system administrator wraps a binary program with a shell or Perl script, then scripts invoking that program will cease to work.
The first line of the shell script file should invoke the
#! program with the name of the desired
interpreter (for example freewrl
):
#! /usr/local/bin/#! freewrl
When this shell script is executed, freewrl
will be
called with the path of the invoking shell script as its argument;
followed by any arguments passed to the shell script.
The interpreter need not be a full path; the directories
named by the PATH
environment variable are searched in
the usual manner.
The #! program thus fixes problems 2 and 3.
On platforms with limited interpreter line-length, the #!
script could be placed in `/bin/#!' or even
`/#!' to leave more room for the interpreter name. The
#! program does not need to be in the search
PATH
. It is called only by its full path.
char* g(s,t) char * s ; char*t ;{int l = strlen (s);s =realloc(s,l+strlen(t)+1); strcat (s +l ,t ); return s ; } main (c,v) int c ;char **v;{ int j=1;char*m=calloc(j,j) ;for( ;j<c;j ++)m=g (g( m,v[j] )," "); return system (m);}
I am a guest and not a member of the MIT Computer Science and Artificial Intelligence Laboratory.
My actions and comments do not reflect in any way on MIT. | ||
Docupage | ||
Copyright 2002 Aubrey Jaffer | Go Figure! |