Changing the default shell without chsh or administrator privileges
If you want to execute zsh instead of bash, just replace /usr/local/bin/bash
by the path to the zsh
executable. Note that this snippet is specific to csh; if your login shell is not (t)csh, this code in ~/.login
won't do anything for you.
As for why the snippet was written that way, you'd have to ask the person who wrote it. [Checks who that was.] Oh. Well, if you just do exec /usr/local/bin/bash
then you won't be starting a login shell, so your .profile
won't be executed. But this could be resolved in a simpler way by executing /usr/local/bin/bash --login
.
Now, if your login shell is not csh, you'll want a different snippet around exec
. In Bourne-style shells, including zsh:
if [ -x ~/bin/zsh ]; then exec ~/bin/zsh; fi
Make that exec ~/bin/zsh -l
if you want the new instance of zsh to read your ~/.zprofile
. Note that if you do that, the snippet above must be in your .profile
or .bash_profile
; if your login shell is zsh, don't put the snippet in your .zprofile
, or else make very sure that the new instance of zsh isn't going to call that exec
again.
Related videos on Youtube
Amelio Vazquez-Reina
I'm passionate about people, technology and research. Some of my favorite quotes: "Far better an approximate answer to the right question than an exact answer to the wrong question" -- J. Tukey, 1962. "Your title makes you a manager, your people make you a leader" -- Donna Dubinsky, quoted in "Trillion Dollar Coach", 2019.
Updated on September 18, 2022Comments
-
Amelio Vazquez-Reina over 1 year
I saw the following snippet in this thread: How to change from csh to bash as default shell
sleep 2 if (-x /usr/local/bin/bash) then exec /bin/sh -c '. ~/.profile; exec /usr/local/bin/bash' endif
My understanding is that if you place this snippet in
~/.login
it will invokebash
when you login.I have a similar situation where I would like to use a similar snippet to invoke a version of
zsh
that is different from the default one with which I log in. Part of the reason why I am going through this trouble is because I can't choose my desired version ofzsh
in the options allowed inchsh
, and I don't have administrator privileges.With this:
- How would I change the snippet above to do this when switching between different versions of zsh?
- Why are two
exec
commands needed in the snippet above? What do they do? Also, why does the snippet above usesh
andbash
(the user is supposed to login withcsh
)
-
Amelio Vazquez-Reina over 12 yearsThanks @Gilles. I wrote the following on my
.zprofile
:if [[ $ZSH_VERSION != 4.3.14 ]]; then exec /n/sw/zsh-4.3.14/bin/zsh --login fi
and that seems to work!