ALEX@SU-SIERRA.ARPA (04/12/86)
From: Alex Bronstein <ALEX@SU-SIERRA.ARPA> Hi, I'm encountering weird problems with sh (and sometimes csh) dying on some shell scripts depending on whether or not my first line in the script is a comment like: # This script does this (but not that) (It dies when the comment is there.) I am looking for ANY hint/story/random knowledge concerning # in shell scripts. ANY bit of information will be appreciated. Thanks, Alex -------
dave@onfcanim.UUCP (Dave Martindale) (04/17/86)
In article <237@Shasta.ARPA> ALEX@SU-SIERRA.ARPA writes: >Hi, > I'm encountering weird problems with sh (and sometimes csh) >dying on some shell scripts depending on whether or not my first line in >the script is a comment like: > > I am looking for ANY hint/story/random knowledge concerning ># in shell scripts. In the beginning, there was only the one true shell, and it knew that shell scripts were to be run by itself. In recent times, many versions of UNIX support the convention that a script beginning with #! signals that a particular (arbitrary) program is to be used to execute the script, and invoking the correct interpreter is handled by the kernel. Sometime in between those two times, there existed UNIX systems that had both a "sh" shell and a "csh" shell but no "#!" mechanism, and the shells (or at least the csh) established a convention that a shell script the began with a comment ('#') was a csh script, otherwise it was a sh script. So, your shell is probably one of these shells, and is deciding to run either sh or csh depending on where you put your first comment. Since the control structures for sh and csh are so different, no wonder the chosen shell gets indigestion if fed a script written for the other shell. Note that even if your kernel does support #!, the old code in the sh/csh may not have been disabled. But it doesn't matter - if you do have #!, just begin your scripts with "#! /bin/sh" or "#! /bin/csh -f" as appropriate.
chris@umcp-cs.UUCP (Chris Torek) (04/17/86)
In article <237@Shasta.ARPA> ALEX@SU-SIERRA.ARPA writes: > I'm encountering weird problems with sh (and sometimes csh) >dying on some shell scripts depending on whether or not my first line in >the script is a comment like: ># This script does this (but not that) Once upon a time, there was the shell. Since there was only `the' shell, there was no trouble deciding how to run a script: run it with *the* shell. It worked, and everyone was happy. Along came progress, and wrote another shell. The people thought this was good, for now they could choose their own shell. So some chose the one, and some the other, and they wrote shell scripts and were happy. But one day someone who used the `other' shell ran a script by someone who use the `other other' shell, and alas! it bombed spectacularly. The people wailed and called upon their Guru for help. `Well,' said the Guru, `I see the problem. The one shell and the other are not compatible. We need to make sure that the shells know which other shell to use to run each script. And lo! the one shell has a ``comment'' called ``:'', and the other a true comment called ``#''. I hereby decree that henceforth, the one shell will run scripts that start with ``:'', and the other those that start with ``#''.' And it was so, and the people were happy. But progress was not finished. This time he noticed that only shells ran scripts, and thought that if the kernel too could run scripts, that this would be good, and the people would be happy. So he wrote more code, and now the kernel could run scripts, but only if they began with the magic incantation: `#!', and told the kernel which shell ran the script. And it was so, and the people were confused. For the `#!' looked like a `comment'. Though the kernel could see the `#!' and run a shell, it would not do so unless certain magic bits were set. And if the incantation were mispronounced, that too could stop the kernel, which after all was not omniscient. And so the people wailed, but alas!, the Guru did not respond. And so it was, and still it is today. * * * * * Anyway, you will get best results from a 4BSD machine by using #! /bin/sh or #! /bin/csh as the first line of your script. `#! /bin/csh -f' is also helpful on occasion. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu
badri@ur-helheim.UUCP (Badri Lokanathan) (04/18/86)
In article <237@Shasta.ARPA> ALEX@SU-SIERRA.ARPA writes: >From: Alex Bronstein <ALEX@SU-SIERRA.ARPA> > >Hi, > I'm encountering weird problems with sh (and sometimes csh) >dying on some shell scripts depending on whether or not my first line in >the script is a comment like: ># This script does this (but not that) > >(It dies when the comment is there.) > > I am looking for ANY hint/story/random knowledge concerning ># in shell scripts. > # in the first column preceeds comments in shell scripts EXCEPT if it is the very first character of the file. The BSD 4.2 csh(1) page mentions this at the bottom of page 18 (?)
campbell@maynard.UUCP (Larry Campbell) (04/18/86)
> From: Alex Bronstein <ALEX@SU-SIERRA.ARPA> > I'm encountering weird problems with sh (and sometimes csh) > dying on some shell scripts depending on whether or not my first line in > the script is a comment like: > # This script does this (but not that) > > I am looking for ANY hint/story/random knowledge concerning > # in shell scripts. Early versions of the Bourne shell (like the one shipped with VENIX 2.0) did not recognize # as a comment delimiter -- in fact it didn't have ANY comment delimiter. I worked around this partially by creating a zero-length executable file called /bin/#. That works as long as there are no shell metacharacters in the comment. If there are, you're out of luck. -- Larry Campbell The Boston Software Works, Inc. ARPA: maynard.UUCP:campbell@harvard.ARPA 120 Fulton Street UUCP: {harvard,cbosgd}!wjh12!maynard!campbell Boston MA 02109