Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ptsfa!ames!hc!beta!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.UUCP Newsgroups: comp.unix.questions Subject: Re: Why does this shell program run under csh???? Message-ID: <5943@brl-smoke.ARPA> Date: Thu, 4-Jun-87 00:03:42 EDT Article-I.D.: brl-smok.5943 Posted: Thu Jun 4 00:03:42 1987 Date-Received: Sat, 6-Jun-87 05:36:51 EDT References: <243@kosman.UUCP> <1270@ssc-vax.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 19 In article <1270@ssc-vax.UUCP> ray3rd@ssc-vax.UUCP (Ray E Saddler III) writes: >#!/bin/sh I guess it's about time to repeat the explanation: UNIX shells attempt run a command via the exec() system call, and if it fails because the command file does not have valid format for an executable binary, then they assume it must be a shell script. Many implementations of csh stupidly then peek at the first character of the script and if it's "#" they assume it must be a csh script rather than an sh script. (That's a BUG. All my sh scripts but one start with "#".) What #! etc. does is that on SOME kernels (such as 4.nBSD) the kernel thereby recognizes that the command file is input for an interpreter and "succeeds" in the exec() system call by running the interpreter for you. This is convenient but kludgy (sorry, Dennis). Therefore the invoking shell never enters the code that would take over when an exec() fails.