Path: utzoo!attcan!uunet!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: Line at a time scripts in csh Message-ID: <898@auspex.UUCP> Date: 27 Jan 89 09:00:52 GMT References: <4116@paris.ics.uci.edu> <909@ubu.warwick.UUCP> <7296@ihlpf.ATT.COM> <872@auspex.UUCP> <7372@ihlpf.ATT.COM> <891@auspex.UUCP> <7449@ihlpf.ATT.COM> Reply-To: guy@auspex.UUCP (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 40 >Why was a "sh" child produced, instead of another "csh" (or, anyway, >a "ksh", which is my login shell, and the value of SHELL)? Any ideas? A long time ago, in a galaxy far, far away (well, I dunno, how far is Berkeley, CA from Napierville, IL?), Bill Joy wrote a shell for either V6 or V7 UNIX. At least when run under V7, it wasn't compatible with the existing UNIX shell; since people wanted to use the C shell as their login shell, and possibly write C shell scripts, but still be able to run Bourne shell scripts as well, both the Bourne and C shells were hacked up to try to recognize each other's scripts and run the other shell if they recognized a "foreign" script. The versions of the Bourne and C shells that I'm familar with that do this check the first character of the script; the C shell assumes that a script beginning with ":" is a Bourne shell script, and the Bourne shell assumes that a script beginning with "#" is a C-shell script. (":" was a no-op command used as a sort of comment in the Bourne shell; the C shell accepted comments beginning with "#" which were *real* comments not scanned by its parser, so ":" tended not to be used in C shell scripts, and since the Bourne shell did not originally have "#" comments, "#" tended not to be used in Bourne shell scripts.) (Subsequently, Berkeley added the "#!" mechanism - suggested, I'm told, by Dennis Ritchie - that allows "exec" system calls to "directly" execute shell scripts; the kernel recognizes "#!" as the first two characters of a file it's told to execute, and sucks a pathname from the first line of the file and runs the program with that pathname, handing it the pathname of the file it was originally told to execute as an argument. This obviates the need for the Bourne/C shell hacks, and just in time - more recent Bourne shells support "#" comments, so you can't validly use "#" as the first character as the deciding factor any more.) >Parenthetically, I did the same sort of thing with "ksh" instead of "csh", >and another "ksh" (NOT a "sh") was forked to run the "ps". Yup, "ksh" basically thinks of itself as the only shell in the world (as did the original Bourne shell), and if it tries to "exec" a program and fails because it's not an executable image, it kicks off another "ksh" to run it. ("#!" allows you to mark shells as Bourne, C, or Korn shell scripts - or as "awk" scripts, or....)