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

Re: exec -l



On 2007-04-29 at 17:52 -0700, Dave Yost wrote:
>  Why does zsh not have "exec -l" a la bash?

Because zsh had already introduced its own non-standard way to do the
same thing before bash added its own non-standard extension?  And
nobody's pushed to copy bash's behaviour?  And ksh has yet another way.
So there's no portable method and nobody's yet contributed code to zsh
to copy the interface provided by other shells.

The Single Unix Specification v3 doesn't include any flags for exec.
(Look in the XCU section).  Zsh does not provide any flags.

In zsh, you can put a "-" at the start of any external command by using
the "-" builtin command.  It's the first builtin listed in
zshbuiltins.1.  So, you'd do:

  exec - cmd

so that you exec cmd with argv[0] being "-cmd".  Or just "- cmd" to run
it as a child process.

Alternatively, zsh lets you specify _any_ string as argv[0] for a new
command by ensuring that the variable ARGV0 is set in the environment
when you run it.  So, for instance, you can do:

 ARGV0=-sh exec zsh

to exec zsh with argv[0] set to "-sh", such that zsh will emulate a
POSIX "sh" more closely and do so as a login shell.  This is what in ksh
would be "exec -a -sh zsh".

-Phil



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