Path: utzoo!attcan!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: How does #!/bin/sh work ? Why does it sometimes not ? Message-ID: <7942@star.cs.vu.nl> Date: 13 Oct 90 00:11:55 GMT References: <7980005@hpopd.HP.COM> <397@inews.intel.com> Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 24 In article <397@inews.intel.com>, bhoughto@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