Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!sunybcs!ugkamins From: ugkamins@sunybcs.uucp (John Kaminski) Newsgroups: comp.unix.wizards Subject: Re: exec() with executable shell scripts Keywords: exec() sh Message-ID: <5413@cs.Buffalo.EDU> Date: 22 Apr 89 04:42:18 GMT References: <647@mqcomp.oz> Sender: nobody@cs.Buffalo.EDU Reply-To: ugkamins@sunybcs.UUCP (John Kaminski) Organization: SUNY/Buffalo Computer Science Lines: 19 In article <647@mqcomp.oz> martin@mqcomp.oz (Martin Foord) writes: > >Everytime I seem to exec() a shell script that is executable I have problems >(execepting if I use execlp() or execvp()). >For example, the program (where /bin/true is an executable shell script) : [ short example of a C program that calls execv() deleted ] > Why is this ? Is it because /bin/true is a shell script because >othere executable non-shell scripts work fine. > >maf. Bingo. When exec() is invoked, it expects to find a "magic number" in the beginning of the file somewhere that identifies to the kernel that this is something that can be loaded into core and be executed directly by the processor. When shell scripts are invoked, the shell must be exec'ed some- how to interpret the text in the file. I believe that the one exception on most systems is the case where the file length is zero, whereby the process just returns the true exit status. I notice that true on a SysV system is length zero.