Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!seismo!mcnc!xanth!john From: john@xanth.UUCP Newsgroups: comp.unix.questions Subject: Re: why does this script... ( : and # ) Message-ID: <1276@xanth.UUCP> Date: Tue, 16-Jun-87 10:22:43 EDT Article-I.D.: xanth.1276 Posted: Tue Jun 16 10:22:43 1987 Date-Received: Thu, 18-Jun-87 03:32:05 EDT References: <913@rtech.UUCP> Organization: Old Dominion University, Norfolk Va. Lines: 47 In article <913@rtech.UUCP>, daveb@rtech.UUCP (Dave Brower) writes: > It's clear you can't have a '#', because that implies csh on some kernels. > You can't rely on '#!/bin/sh', because some kernels don't undertand it. > (Yes, there are some that recoginize '#', but not '#!/..."). You say "kernels" above, but I hope you mean "distributions of UNIX operating systems" or something like that. The whole point of #! is that the ->kernel<- understands it and runs the specified interpreter, as opposed to just the # which the ->csh<- understands to mean "use the csh", and the newer Bourne shells just consider a comment. So yes, it's certainly true that there are plenty of versions of UNIX out there where the kernel does not understand #! but the csh understands # - all version of System V with the csh, for example. (If there are System V kernels that do #!, please let me know!) I think we should end this discussion with a quick summary of the situation. Here is a table describing which shell your script will be run by, depending on what it begins with, and where you're running it from. The "sh" here is a Bourne shell that uses "#" as a comment; if not, the situation's even worse. script r u n f r o m begins kernel knows #! kernel does not know #! with sh csh sh csh #! -- specified script -- sh csh # sh csh sh csh other sh sh sh sh (includ- ing :) So if you're writing a csh script, the best you can do is to start it with #! /bin/csh and hope no one tries to run it from the Bourne shell under a kernel that does not know #!. If you're writing a Bourne shell script, you should start it with something else, like a colon alone on the line, as Dave suggests, and it will always be run by sh. Only if you know the script will never go to a system that does not know #! should you use #!/bin/sh . -- John Owens Old Dominion University - Norfolk, Virginia, USA john@ODU.EDU old arpa: john%odu.edu@RELAY.CS.NET +1 804 440 4529 old uucp: {seismo,harvard,sun,hoptoad}!xanth!john