From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Fri, 15 Jul 2005 14:30:06 -0400 From: Dan Cross To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Subject: Re: [9fans] #!/bin/foo Message-ID: <20050715183006.GA21802@augusta.math.psu.edu> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i Topicbox-Message-UUID: 67e2517c-ead0-11e9-9d60-3106f5b1d025 On Fri, Jul 15, 2005 at 06:09:11AM +0900, arisawa@ar.aichi-u.ac.jp wrote: > A file with a executable bit and a starting line > #!/bin/foo > is executable if foo is executable binary. > But the file fails execution if foo is a script. > Isn't this inconvenient? It is, but it's to prevent an endless loop.... Imagine if you had a script named /usr/someone/blah that started, ``#!/usr/someone/blah''. It would try to recursively start itself as a script, and the kernel would (potentially) go into an endless loop. Of course, it would be silly and pathological for someone to do something as simple as this on purpose, but one could imagine a circular graph being inadventantly created out of a chain of interpreters that did the same thing (e.g., interp1 calls interp2 that calls interp3 that calls interp1 again). You could try and prevent it by setting a counter in the kernel of the number of times you've invoked an interpreter when trying to run a program, but that could potentially break down, so it was probably deemed easier to just prevent the whole practice. Under Unix, you could probably get around it by doing something like, #!/usr/bin/env script-to-use-as-interpreter. Some similar wrapper could probably be written for Plan 9 to achieve the same effect. - Dan C.