Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How do I change the subshell to something other than /bin/sh?

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

ARGV0=sh bash ./x.sh


Messages sorted by: Reverse Date, Date, Thread, Author