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

Re: "exec zsh" inside .zprofile doesn't set SHELL

On Sep 22, 12:14am, Clint Olsen wrote:
} Subject: Re: "exec zsh" inside .zprofile doesn't set SHELL
} I'm executing this in my .zprofile (nothing fancy).  So far, I've not had
} any problems with looping execs.  Apparently the results of "exec $SHELL"
} doesn't make it a login shell again.  Am I overlooking something?

That's right, "exec zsh" will not propagate login-shell-ness.  The best you
can do is "exec zsh -$-" which passes to the new zsh all the setopts of the
current one that can be represented as command-line flags.  That _will_
propagate login-ness, so then you need something like

    [[ "$ZSH_VERSION" = 3.0.5 ]] && export SHELL==zsh && exec $SHELL -$-

The problem with testing version numbers is that, whichever way you do the
equality (equal the old version or not-equal the new one), the wrong thing
may happen if one or the other gets upgraded.  And if for some reason the
output of =zsh is the path to the old version, you still have a loop.  So
IMO a better solution is

    export SHELL==zsh && export ZDOTDIR=$HOME/.myzsh && exec $SHELL -$-

The files in .myzsh can be links to the ones in $HOME (or in your regular
$ZDOTDIR if there is one) *except* for the one that contains the "exec",
so you can't possibly hit that more than once.

On a consulting job I did a while back the system zsh was version 2.4 (!!)
so I quickly compiled a 3.0.5 and set it up like this:

~/.zprofile contained:

    [[ -f ~/.myzsh/.zprofile ]] && source ~/.myzsh/.zprofile
    if ~/bin/zsh -fc 'exit 0'; then
	export SHELL=$HOME/bin/zsh
	export ZDOTDIR=$HOME/.myzsh
	exec $SHELL -$-

~/.myzsh/.zprofile didn't exist, that "source" was for completeness.

~/.zshenv and ~/.zlogin had a lot of skeleton setup stuff for my client's
local build environment, so left them alone.

~/.myzsh/.zshenv contained a "source ~/.zshenv" followed by some extra
setup stuff for 3.0.5.

~/.myzsh/.zlogin was the .zlogin that I cart around with me everywhere,
that handles every version of zsh from 2.0 through (then) 3.1.5 and makes
them act as much alike as possible, with "source ~/.zlogin" stuck in at a
strategic point.

~/.myzsh/.zlogout was a symlink to ~/.zlogout.

~/.zshrc was the version 2.4 initialization stuff.
~/.myzsh/.zshrc was my 3.0.5 initialization stuff.

Running zsh -fc in the "if" test was in case I logged in to a machine
that wasn't the same architecture as the one on which I built ~/bin/zsh;
they had a small number that were different, but I don't think I ever
actually used one.  Anyway, the end result was that I'd launch 3.0.5 but
duplicate reading only of the zshenv files, while falling through if my
homebuilt zsh didn't work for some reason.

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

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