4

I referred to this answer to change my default shell How to change default shell to ZSH - chsh says "invalid shell"

After adding zsh to /etc/shells and doing sudo chsh -s "$(command -v zsh)" "${USER}" I ran echo $SHELL (which gave no output btw so I thought that it must have ran successfully) and it gave me /bin/bash

I closed my shell and opened up a new shell session and zsh showed up so I thought it must have been fixed with a restart, after that when I ran echo $SHELL in the zsh session it still gave me the same output /bin/bash``$SHELL --version also gives me the bash version not the zsh one

everytime I do ctrl+alt+t I do get a zsh session but this echo $SHELL output is making me suspicious.

UPDATE: I am running Ubuntu Budgie 18.04.3 and I got /bin/zsh from echo $0

  • I guess, its normal behaviour. I just tried in my macos. I use bash as my default shell. So I changed my default shell to zsh and then echo $SHELL it gave me: /usr/local/bin/bash I guess you will need to change your environment variable, the output you get from printenv – Rakib Fiha Dec 21 '19 at 13:07
  • Hi, you just said that you use bash as your default and that is why it gives you bash when you echo $SHELL but in my case I used chsh to change my default (you don't mention changing your default). I don't see how your case is similar to mine? – Palash Nigam Dec 21 '19 at 13:09
  • 1
    What output you get from echo $0 ? Could you add that in your question ? – Rakib Fiha Dec 21 '19 at 13:11
  • I got /bin/zsh from echo $0 @RakibFiha – Palash Nigam Dec 21 '19 at 13:13
  • Ok, just made sure that you are in zsh shell. What happens if you export SHELL=/bin/zsh ? – Rakib Fiha Dec 21 '19 at 13:27
  • su --login $USER I did this in my current zsh session and echo $SHELL gave me zsh this time but I am gonna have to do it everytime I start a new shell session is there anyway workaround for this? – Palash Nigam Dec 21 '19 at 13:38
  • 1
    @palash25 Reboot or log out completely. Then log in again. That's your workaround. SHELL is only set when you log in. – Kusalananda Dec 21 '19 at 13:42
  • that worked thanks – Palash Nigam Dec 21 '19 at 13:52
  • 1
    What this question lacks is an explanation of "opened up a new shell session". Starting a fresh instance of a GUI terminal emulator within the same GUI login session is not the same as logging off and back on again, nor is it the same as a TUI login session. And exactly which terminal emulator it is also matters. – JdeBP Dec 21 '19 at 14:22

2 Answers2

5

The SHELL environment variable is only set when you perform a full login, e.g. by logging out and logging in again, or by using su - "$USER" or ssh "$USER@localhost" or some other command that performs a full login.

It is usually the login program that sets this variable based on what the user's login shell is in the passwd database. This is called as part of the login process by whatever process is accepting a login request from a user (e.g. via sshd or gdm etc.)

From the login(1) manual on Ubuntu:

Your user and group ID will be set according to their values in the /etc/passwd file. The value for $HOME, $SHELL, $PATH, $LOGNAME, and $MAIL are set according to the appropriate fields in the password entry. Ulimit, umask and nice values may also be set according to entries in the GECOS field.

Just starting a new shell session will not set this variable's value, not even if the shell is started as a "login shell".

Kusalananda
  • 333,661
1

Wanting to add to Kusalananda's excellent and accepted answer:

On macOS if you want to to see the change without logging out of the GUI you can enter the following in Terminal:

$ logout [your username]

Then open a new Terminal session and enter:

echo $SHELL

You will see your new environment setting.

John
  • 145