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.
On a normally-configured system, if you changed your shell with chsh
, then the chosen shell is valid, so your shell is starting, but there is a problem with one of its configuration files that causes it to exit immediately.
Try pressing Ctrl+C very quickly after logging it. Depending on how loaded the machine is, the time window during which this will not kill the shell but will instruct it to stop parsing configuration files may or may not last long enough to get a realistic chance of success. Try it a few times, ideally during some heavy disk activity so that the files involved aren't in the disk cache.
If the problem is in .zshrc
, you can still log in non-interactively. This is impossible on the console, but can be done over the network:
ssh machinename 'mv .zshrc bad.zshrc'
If you have FTP (not SFTP) access, you can get rid of any configuration file this way, because FTP doesn't read any configuration files. With SSH or SFTP, a shell is always invoked, so you won't be able to log in if the problem is with .zprofile
or .zshenv
.
If you're unable to access your account, you'll need to fix this via the root account. If you have a root password, just log in as root on the console. If you only have access to the root account via sudo, you've locked yourself out, so assuming that nobody else can do it for you, you'll need to have physical access to the machine and you'll need to reboot it. At the bootloader prompt (you may need to press and hold Shift to make it appear), add init=/bin/sh
at the end of the kernel command line (the line that starts with linux
). See the Arch Wiki for more details.
Once you get access from the root account, you may either change the shell back to one that worked, or guess the file that caused the problem. Zsh reads five configuration files in /etc
and 5 in your home directory.
Once you've recovered access to your account, if you don't know what file caused the problem, add set -x
to ~/.zshenv
. This will cause zsh to print all commands before executing them. Run zsh -l
to run a login shell, or log in on another terminal, and see what breaks.
Before changing your shell back to zsh, test that zsh -l
works. After running chsh
, check that you can log in on another terminal before logging out.
Best Answer
To get back into the system you can boot into single user mode by appending the number 1 at the end of the linux kernel line within GRUB. The method for doing this is roughly outlined in this U&L Q&A titled: Can I launch a process as root without launching root's login shell?.
Once you've done this you'll be dropped to a prompt as root from where you'll be able to reverse the changes you made to your shell. This will get your system back so that it's working correctly.
From here you'll likely want to run
chsh
for your username instead of whatever method you employed previously.