Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mgm.mit.edu!wolfgang From: wolfgang@mgm.mit.edu (Wolfgang Rupprecht) Newsgroups: comp.unix.wizards Subject: Re: How does Unix kernel find /bin/sh? Keywords: #!/bin/sh Message-ID: <13855@bloom-beacon.MIT.EDU> Date: 27 Aug 89 15:08:25 GMT References: <5@minya.UUCP> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: wolfgang@mgm.mit.edu (Wolfgang Rupprecht) Organization: Freelance Software Consultant, Washington DC. Lines: 28 In article <5@minya.UUCP> jc@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@mgm.mit.edu (IP 18.82.0.114) TEL: (703) 768-2640 UUCP: mit-eddie!mgm.mit.edu!wolfgang