Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!uw-june!ka From: ka@june.cs.washington.edu (Kenneth Almquist) Newsgroups: comp.unix.wizards Subject: Re: exec() with executable shell scripts Summary: Executing programs that may be shell scripts. Message-ID: <7954@june.cs.washington.edu> Date: 23 Apr 89 09:40:31 GMT References: <647@mqcomp.oz> <520@visdc.UUCP> Organization: U of Washington, Computer Science, Seattle Lines: 20 jiii@visdc.UUCP (John E Van Deusen III) writes: > If you do not want to use [execlp or execvp], you have to do the > following, (I have used execl for clarity): > > execl("/bin/sh", "sh", "-c", "/bin/true", 0); More generally, you can write: execl(program, (char *)0); if (errno == ENOEXEC) { /* it's a shell procedure */ execl("/bin/sh", "sh", program, (char *)0); perror("/bin/sh"); } else { perror(program); } exit(2); Note that if you write "0" in place of "(char *)0" this code will no longer be machine independent Kenneth Almquist