2

From tcsh, if I try:

exec /home/path/to/my/zsh

it works (I enter a Zsh shell)

but if I try

exec -c /home/path/to/my/zsh

I get:

-c Command not found

How do I switch to my Zsh shell and start it from a "blank slate"? (i.e. with no environment variables carried over from tcsh ).

1 Answers1

6

Not sure why you'd want to do that, but you can do:

exec env -i /home/path/to/my/zsh

Probably many things won't work properly as you'll be missing some essential environment variables like $PATH, $HOME or $TERM.

If you want to whitelist a few variables and remove the rest:

exec env -i HOME="$HOME" TERM="$TERM" /home/path/to/my/zsh

If you want to restore the environment at the time tcsh was started, you could insert this to the very beginning of ~/.tcshrc:

sh -c 'export -p' > ~/.initial-env

And then do something like:

exec env -i sh -c ". $HOME/.initial-env; exec /path/to/zsh"

That is save the environment when tcsh starts and restore it when you execute zsh.

If what you want is change your shell to zsh while you don't have to possibility to do a chsh (or zsh is not installed or the one installed is 20 years old), (brings back memory from over 15 years ago (gosh!) when I was in the exact same situation (though with csh instead of tcsh)), you can replace the content of your ~/.login with:

setenv SHELL /path/to/zsh
exec $SHELL -l

And remove your .tcshrc

Setting $SHELL specifies your shell preference (that is what applications like xterm or vi... will start when they need to start a shell for you).

Putting it in your ~/.login should ensure it's only done once. Hopefully, no more tcsh would be started later on during your login session since you've changed $SHELL. It shouldn't matter whether you put your environment variable definitions in ~/.login or ~/.zprofile or ~/.profile. It's up to you.

Test with tcsh -l before logging out.

  • Thanks! To answer your first question. I don't have admin privileges to change my default shell, and I would like to specify my env. variables directly in my .zshrc, since Zsh is the only interactive shell that I use. Does my approach to this problem make sense? – Amelio Vazquez-Reina Mar 11 '13 at 21:26
  • 2
    @user815423426 You don't need, and indeed should not, remove environment variables. Just do exec /home/path/to/my/zsh or rather exec /home/path/to/my/zsh -l to make zsh load ~/.zprofile. If there's some environment variable you don't want, unset it in your .zprofile. – Gilles 'SO- stop being evil' Mar 11 '13 at 22:48