zsh-users
 help / color / mirror / code / Atom feed
* How do I change the subshell to something other than /bin/sh?
@ 2007-10-04 16:29 Julio Garcia
  2007-10-04 16:43 ` Stephane Chazelas
  2007-10-04 16:45 ` Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Julio Garcia @ 2007-10-04 16:29 UTC (permalink / raw)
  To: zsh-users

Hello,

I am sorry if this has been answered already. I could not find and answer 
with google.

My problem is this. I am trying to run some scripts that I cannot change 
which assume capabilities found in bash. I know that zsh will execute them 
correctly as well. However, when I just invoke them from the zsh command 
line, they run under /bin/sh and fail. For example, I have a test script 
that looks like this:

logsol10-1 ~ > cat x.sh

echo $0

ps

The output when I run it is this:

logsol10-1 ~ > ./x.sh
./x.sh
   PID TTY         TIME CMD
24296 pts/8       0:00 zsh
  5205 pts/8       0:00 ps
  5204 pts/8       0:00 sh

Note that it execs sh. How can I tell it to use another shell? zsh or bash, 
for example?

Thanks,

Julio

_________________________________________________________________
More photos; more messages; more whatever. Windows Live Hotmail - NOW with 
5GB storage. 
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_5G_0907


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How do I change the subshell to something other than /bin/sh?
  2007-10-04 16:29 How do I change the subshell to something other than /bin/sh? Julio Garcia
@ 2007-10-04 16:43 ` Stephane Chazelas
  2007-10-04 16:45 ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Stephane Chazelas @ 2007-10-04 16:43 UTC (permalink / raw)
  To: Julio Garcia; +Cc: zsh-users

On Thu, Oct 04, 2007 at 10:29:49AM -0600, Julio Garcia wrote:
[...]
> logsol10-1 ~ > ./x.sh
> ./x.sh
>   PID TTY         TIME CMD
> 24296 pts/8       0:00 zsh
>  5205 pts/8       0:00 ps
>  5204 pts/8       0:00 sh
>
> Note that it execs sh. How can I tell it to use another shell? zsh or bash, 
> for example?
[...]

You probably shouldn't do that. It's probably safer to trust zsh
for the current setting. Normally, if you write POSIX scripts,
you should *not* use the "#! /bin/sh -" lines, and trust the
"system" (if you're in a POSIX environment) for calling the
right shell (that is a POSIX one, which zsh is not by default)
to interpret the file. In the case of zsh, it's not actually the
"system" that decides what shell to call, but zsh. But zsh
should be setup to try and use the same shell as the "system"
would use.

Hmmm, looking at the code, looks like zsh has "/bin/sh"
hardcoded as the path of that shell. That makes it not POSIX on
systems where the POSIX shell is not in /bin like on Solaris.
(on Solaris, execvp(), system()... may call /bin/sh or a
standard shell depending on how you link the executable that
uses those functions).

Given that it's hardcoded, I don't think there's a way you can
change the shell zsh uses in this case.

But you can run call the interpreter directly: bash ./x.sh or
/usr/xpg4/bin/sh ./x.sh.

Or, if you want to call bash as "sh" for it to behave more
POSIXly:

ARGV0=sh bash ./x.sh

-- 
Stéphane


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How do I change the subshell to something other than /bin/sh?
  2007-10-04 16:29 How do I change the subshell to something other than /bin/sh? Julio Garcia
  2007-10-04 16:43 ` Stephane Chazelas
@ 2007-10-04 16:45 ` Peter Stephenson
  2007-10-04 18:04   ` Stephane Chazelas
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2007-10-04 16:45 UTC (permalink / raw)
  To: zsh-users

"Julio Garcia" wrote:
> My problem is this. I am trying to run some scripts that I cannot change 
> which assume capabilities found in bash. I know that zsh will execute them 
> correctly as well. However, when I just invoke them from the zsh command 
> line, they run under /bin/sh and fail. For example, I have a test script 
> that looks like this:
> 
> logsol10-1 ~ > cat x.sh
> 
> echo $0
> 
> ps

If you really can't change the script (and hence can't add a #! line),
you are stuck with running "zsh ./x.sh" wherever you call the script, or
some equivalent of that.  The decision about which interpreter to run
for a file that isn't executable is made by the operating system, so
the's no way of changing it at the user level.  So the question is
really about how you're calling the script and how much you can change
at that point.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How do I change the subshell to something other than /bin/sh?
  2007-10-04 16:45 ` Peter Stephenson
@ 2007-10-04 18:04   ` Stephane Chazelas
  0 siblings, 0 replies; 4+ messages in thread
From: Stephane Chazelas @ 2007-10-04 18:04 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

On Thu, Oct 04, 2007 at 05:45:07PM +0100, Peter Stephenson wrote:
> "Julio Garcia" wrote:
> > My problem is this. I am trying to run some scripts that I cannot change 
> > which assume capabilities found in bash. I know that zsh will execute them 
> > correctly as well. However, when I just invoke them from the zsh command 
> > line, they run under /bin/sh and fail. For example, I have a test script 
> > that looks like this:
> > 
> > logsol10-1 ~ > cat x.sh
> > 
> > echo $0
> > 
> > ps
> 
> If you really can't change the script (and hence can't add a #! line),
> you are stuck with running "zsh ./x.sh" wherever you call the script, or
> some equivalent of that.  The decision about which interpreter to run
> for a file that isn't executable is made by the operating system, so
> the's no way of changing it at the user level.  So the question is
> really about how you're calling the script and how much you can change
> at that point.
[...]

On most system, the execve() of a script that doesn't have a #!
line will return with ENOEXEC. In which case, it will be zsh
that will run /bin/sh (if it doesn't find a NUL character in the
first 64 bytes of the file).

That's also what the exec*p() type libc functions do, except that
those may not run /bin/sh but whichever shell is required by the
standard they implement and don't search for NUL bytes.

Maybe in sh emulation, zsh could call itself in sh emulation in
that case?

-- 
Stéphane


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-10-04 18:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-04 16:29 How do I change the subshell to something other than /bin/sh? Julio Garcia
2007-10-04 16:43 ` Stephane Chazelas
2007-10-04 16:45 ` Peter Stephenson
2007-10-04 18:04   ` Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).