exec() with executable shell scripts

John Kaminski ugkamins at sunybcs.uucp
Sat Apr 22 14:42:18 AEST 1989


In article <647 at mqcomp.oz> martin at 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.



More information about the Comp.unix.wizards mailing list