How does Unix kernel find /bin/sh?

Wolfgang Rupprecht wolfgang at mgm.mit.edu
Mon Aug 28 01:08:25 AEST 1989


In article <5 at minya.UUCP> jc at minya.UUCP (John Chambers) writes:
[ questions on replacing /bin/sh w. a dispatcher for the #!/bin/foo
first line in shell scripts ]
>The problem is simple:  when I exec a script directly, the kernel
>doesn't run /bin/sh, it runs /bin/bsh!  I can prove this easily [...]

Its *not* the kernel.  It is /bin/sh (called /bin/bsh in your system)
that is taking the short-cut.

The real /bin/sh doesn't need to exec a copy of /bin/sh.  It knows
that it is the "True" /bin/sh and simply forks passing the command 
file's ascii contents to the forked copy of itself.

I executing a non-builtin is done roughly like this:

	if (fork == 0)
	{
		execle(command_name, ...);
	    /* what, still here?  Must be a shell script, run it ourselves */
	        top_lev_shell_interpreter(fopen(command_name), ...);
		exit(...);
	}else
		wait(...);

-wolfgang
----
Wolfgang Rupprecht	ARPA:  wolfgang at mgm.mit.edu (IP 18.82.0.114)
TEL: (703) 768-2640	UUCP:  mit-eddie!mgm.mit.edu!wolfgang



More information about the Comp.unix.wizards mailing list