How does #!/bin/sh work ? Why does it sometimes not ?

Maarten Litmaath maart at cs.vu.nl
Sat Oct 13 10:11:55 AEST 1990


In article <397 at inews.intel.com>,
	bhoughto at cmdnfs.intel.com (Blair P. Houghton) writes:
)...
)When execve(2) sees '#!' (hex 2321) it interprets the rest
)of the line as the pathname to an interpreter, and its
)arguments; it opens _that_ file as an executable, and pipes
)it the balance of the first file as input.

Wrong.  If the file `foo' has `#!/bin/sh' as its first line,
executing `foo' will result in `/bin/sh foo', i.e. the filename
is passed as an _argument_.

If the rest of the file were passed as input to the interpreter,
e.g. the following example would not work:

	#!/bin/sh

	echo 'Give the name:'
	read name
	echo "The name is: $name"

Issuing the command `sh < foo' would have the same unwanted effects.
--
Waiting for this to work: cat /internet/cs.vu.nl/finger/maart



More information about the Comp.unix.questions mailing list