[net.unix-wizards] #! /bin/foo

whm@sri-unix (10/31/82)

Using the #! mechanism does not work with every command interpreter.
If you start a file with #! /bin/foo, and make the file executable,
running the file will cause /bin/foo to started up with the file
as standard input.  If /bin/foo doesn't know what to do with a
line of the form, #! ..., it's trouble.  I presume that make and
awk work because they use # as a comment character.  This mechanism
is extremely powerful and useful, I'm surprised that nobody has
done it before now.  I guess a ramification of this is that # is
being locked in as a "global" comment character for programs that
interpret scripts.

It also should be pointed out that #! need not only be used with
ascii text files, it can be used with "binary" files as well.  I
used this feature to make files produced by our Icon interpreter
translator directly executable.  Thus, instead of having to
say "iconx program-name", you just say "program-name".  I was
going to say that Berkeley Pascal should use this as well, but
I see that "obj" files produced by pi are "executable", although
they don't use the "#!" mechanism.

For enlightenment, try:
	cat >xtest
	#! /bin/cat
	This
	is it.
	^D
	chmod +x xtest
	xtest
It's also fun to try "adb xtest".