4

I am using 'zsh' by default.

But when I am in my zsh shell, I enter 'bash' to switch to bash, why the $SHELL variable does not change?

Can I make screen to use whatever shell I right before execute the 'screen' command?

zsh % screen
<the shell is zsh>

zsh % bash
bash $ screen
<the shell is still bash, can I make screen to automatically start bash here>

1 Answer 1

9

The SHELL variable (along with some other variables, such as HOME and USER) is set by the process that logs you in. It is set to the login shell value set in the passwd database (/etc/passwd). It is not meant to reflect the shell you're currently using.

screen uses the SHELL variable to determine what shell to run inside the screen, so you can override that by running e.g.

SHELL=/bin/bash screen

And if you want bash to be your login shell instead of zsh, you can run the chsh (change shell) command as your user.

5
  • Is there any way to get the current shell? I usually do ps -p $$ to find out the current shell. But is there any better way? May 11, 2016 at 11:32
  • @ecerulm, that's really the most reliable way I know of.
    – geirha
    May 11, 2016 at 13:00
  • Is there any way to change this without logging out or restarting the computer? Opening a new shell leaves the $SHELL variable alone. My computer came straight from the manufacturer with Ubuntu installed, could that be part of the problem?
    – trysis
    Jun 30, 2018 at 6:30
  • @trysis I assume you want new terminal windows to start the new shell you've changed to, but since SHELL is set during login, you get the old shell. Until you've logged in I'm afraid your best bet is to run SHELL=/bin/othersh exec /bin/othersh in every new terminal window.
    – geirha
    Jul 1, 2018 at 7:21
  • OK, thanks, I think I'll re-login unless I really need something still open, in which case I'll re-login the instant I don't.
    – trysis
    Jul 2, 2018 at 0:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .