Subject: Re: HELP : some newbie questions
To: Colin Wood <cwood@ichips.intel.com>
From: Henry B. Hotz <hotz@jpl.nasa.gov>
List: port-mac68k
Date: 02/13/1998 15:41:27
At 1:21 PM -0800 2/13/98, Colin Wood wrote:
>Henry B. Hotz wrote:
>> Executable files are handled by the current shell (usually csh for netbsd,
>> but usually sh for system scripts on other systems).  All standard, current
>> unix shells are programmed to look for a special format comment line at the
>> beginning of any script and if it points to a valid shell to switch to that
>> shell instead of processing the script themselves.
>
>Actually, I'm pretty sure that all the shell does is pass it's arguments
>to exec() once it's handled all the shell metacharacters.  The actual
>deciphering of the magic number and the handoff to an interpreter (if its
>a text file instead of an excutable binary) is handled by exec(), which is
>either implemented in a library or the kernel itself (I don't know which
>without checking the source, but I think it's in libc under NetBSD).
>Looking at the source for /bin/sh, it appears to support doing the
>interpretation itself if it's not built into the kernel.  I'm pretty sure
>we have it built into the kernel (via execvp()).  Someone please correct
>me if I'm wrong.

According to man exec:
     If the header of a file isn't recognized (the attempted execve returned
     ENOEXEC), these functions will execute the shell with the path of the
     file as its first argument.  (If this attempt fails, no further searching
     is done.)

In addition the Files: section specifically references /bin/sh.  So I can
stand my my statement that it's the shell doing the switching, but it
appears to always be /bin/sh that's tried first, not what your current
shell is.

>> Since the test case he used is valid in any standard Unix shell he probably
>> doesn't have "." in his $PATH.  (Maybe he read that warning about not
>> having "." in the root path and did something about it!)
>
>Well, in this case, he didn't say that he was in the /root/pub directory,
>so I didn't assume that ./file would work.  Do we ship with "." in root's
>path by default?

If I'm going to correct people I guess I should make sure I'm right.

We used to ship with "." at the end of $PATH, and there was a warning
message that would get printed out about it and we were always getting
questioned about what was wrong with the system when a newby got the
message and didn't understand it.  It appears that in 1.3 "." is no longer
in the default root $PATH.  Now the annoying FAQ-causing message is "Don't
login as root, use the su command."

Signature failed Preliminary Design Review.
Feasibility of a new signature is currently being evaluated.
h.b.hotz@jpl.nasa.gov, or hbhotz@oxy.edu