19

I'm having some difficulties in changing the value of $SHELL in OSX's iTerm app. iTerm is starting in /bin/zsh, but the value of $SHELL doesn't seem to change.

What I've done:

  1. Changed "command" as /bin/zsh in iTerm's configuration window.
  2. Executed chsh to change the shell to /bin/zsh.
  3. Confirmed iTerm is started in /bin/zsh

NOTE #1: In OSX's stock terminal app, "Terminal.app":

echo $SHELL
/bin/zsh

NOTE #2: In OSX's popular terminal app, "iTerm.app":

$ echo $SHELL
/bin/bash
$ echo $USER
$ melvkim
$ chsh -s /bin/zsh
Changing shell for melvkim.
Password for melvkim:
chsh: no changes made
athena
12.7k9 gold badges65 silver badges142 bronze badges
asked May 25, 2014 at 0:20
4
  • 1
    Have you looked in /etc/shells ? The manual states that if the shell you specify is not in that file, it isn't considered a standard shell. Commented May 27, 2014 at 2:05
  • You real problem isn’t to change the $SHELL, but your real default shell in iTerm. The variable is built at login shell from the default shell used by iTerm. Commented Aug 7, 2021 at 9:08
  • could you mark your answer as correct to mark the question as answered? You can mark your own answer as a solution. Thanks! Commented Jul 6, 2022 at 22:55
  • If you need to have SHELL set to zsh, do it in your ~/.zshenv: export SHELL=/bin/zsh, or better export SHELL==zshif you want to play around with different zsh versions. SHELL is not a particular zsh variable, but you can set it to any value you want. Commented Nov 9, 2024 at 11:30

8 Answers 8

11

The problem was the "iTerm" app's conflicting settings with the shell. To resolve, I've reset "login shell" command in iTerm preference window:

iTerm.app -> Preferences -> Profiles -> General -> Command -> Click on "Login shell"

Then, I executed chsh to modify it as /bin/zsh.

To reproduce the problem (having $SHELL set as /bin/bash/, even though the login shell is /bin/zsh), I just had to change "iTerm" setting back to "Command: /bin/zsh/".

mmmmmm
31.4k18 gold badges96 silver badges164 bronze badges
answered May 26, 2014 at 18:36
4
  • Buddy of mine had the same issue w/ intelliJ. Commented Sep 22, 2020 at 15:03
  • re: "iTerm.app -> Preferences". I'm a long time Linux user (hence why I'm here) but new to iOs. I just can't find this instruction. More guidance would be appreciated. I really want bash in IOs! Commented Mar 21, 2021 at 11:22
  • 1
    @StephenHosking with iTerm active, do CMD + , to reach Preferences Commented May 12, 2021 at 21:43
  • Remove the / at the end of your iTerm preferences shell path, because it might cause errors in shell scripts. Commented Aug 7, 2021 at 9:11
6

I had a similar issue but I resolved it by executing the command chsh -s /bin/zsh in the terminal,then navigated to

Terminal -> Preferences -> General window

and changed the Shells open with: option to Default login shell while the command (complete path) set to /bin/zsh.This should solve your problem.

answered Jul 5, 2020 at 6:33
0
2

Look here for the excellent explanation and solution posted by @mklement0 [in relation to a bash upgrade problem.

I had a similar problem in doing the opposite on my system (OS X 10.10.1): making bash the default login shell again after I had installed oh-my-zsh, which made zsh the default, and then upgrading bash from 3.2.53 to 4.3.30 using Homebrew (why is Apple shipping Yosemite with an old bash version?).

I think the SHELL environment variable reflects but does not control the actual default login shell for the user. For example, if, say, bash was your default and you open a new bash shell window from terminal then $ export SHELL="/bin/zsh"; echo "$SHELL" would show /bin/zsh but no actual change will occur because if you open a new shell window from terminal and do $ echo 0ドル then you would see -bash (0ドル contains the name and path of the command that started the shell window, in this case bash, and the - next to it indicates that it is a login shell).

As @mklement0 pointed out the actual default login shell for the user is controlled by the UserShell property in the user's record in the system's internal database - this can be queried and updated using the command line utility dscl. This information will passed to your terminal app when you open a shell window.

What chsh -s /bin/zsh does is change this UserShell property to set it to zsh - you can check this by doing dscl . -read /Users/$USER/ UserShell immediately afterwards, and you will see UserShell: /bin/zsh. But the change is not effected in the current window, until you do something like exec su - $USER as suggested by @mklement0, or until you close and open a shell window.

answered Dec 28, 2014 at 23:41
1

The -s flag for chsh only attempts to change the shell, and probably fails due to Open Directory: The usual UNIX system 'chsh' would modify the /etc/passwd entry. However, I was able to run chsh with no arguments, which gave me an editor, and the following information:

# Changing user information for nevin.
# Use "passwd" to change the password.
##
# Open Directory: /Local/Default
##
Shell: /bin/tcsh
Full Name: Nevin Williams
Office Location:
Office Phone:
Home Phone:

I was able to edit the "Shell:" entry to /bin/zsh, and subsequent Terminal windows opened with a Z-shell prompt.

answered May 25, 2014 at 1:58
3
  • I tried chsh with no args. Still no luck. The variable doesn't change. In fact, when the editor was loaded, it showed /bin/zsh. Commented May 25, 2014 at 2:54
  • Try changing the shell with the editor. I made a screen capture of me changing from /bin/tcsh to /bin/zsh and back. bonmot.ca/~nevin/chsh.mov Commented May 25, 2014 at 4:09
  • Thank you very much for taking your time recording posting your screencast! Your solution is supposed to be working on other terminal emulators, but I wasn't abel to change $SHELL on iTerm. Please refer to my answer for details.. Thanks! Commented May 26, 2014 at 18:40
1

Try executing the command: chsh -s /bin/zsh from the default Mac terminal.

answered Feb 7, 2017 at 15:54
2
  • 1
    What does this do differently from the OP? Commented Feb 7, 2017 at 16:12
  • @JMY1000 If you try to execute that command from iTerm, the changes aren't reflected. You should be able to get it working by executing it from Mac's default terminal. Commented Feb 10, 2017 at 2:37
1

I had a similar issue. The Terminal would open into bash. csh -s /bin/zsh would fail with an error. Examining the default shell in System Preferences->Users by control-clicking on my user showed /bin/zsh was set. dscl showed /bin/zsh was set. I tried resetting Terminal->Preferences to /bin/zsh. That also failed.

Ultimately, it turned out there was a lockfile. Going to ~/Library/Preferences, I deleted com.apple.Terminal.plist.lockfile and com.apple.Terminal.plist. That fixed the problem. On the next startup, zsh loaded correctly in the terminal.

mmmmmm
31.4k18 gold badges96 silver badges164 bronze badges
answered Aug 7, 2021 at 0:54
0

As has been mentioned, iTerm's default shell is not changed by modifying the $SHELL variable.

Instead, the "correct" (and most robust) solution is to

  1. change your macOS user default shell to the shell you want to use, and then
  2. leave iTerm2's setting (Profiles -> General -> Command) as simply "Login Shell" in the drop-down

With the iTerm setting as in 2. above, iTerm will then pick what the system tells it to for your user.

For 1. above, again the correct + most robust way to do this is through macOS's Open Directory Service, which is what is ultimately in control of this setting. You can do that in one of the following ways:

  • through macOS System Settings.app
    • the setting is fairly well hidden: (in macOS Sonoma 15.6:) Users & Groups -> Network account server ("Edit...") -> Open Directory Utility... -> click padlock symbol to unlock -> tab "Directory Editor" -> select your user in the left pane (the entry is given with the full name for the user) -> (right pane:) find the key "UserShell" and change the value to the path of the shell you want to use
  • with the terminal command dscl

In this way, the setting is made where macOS wants it to be, and the shell will be invoked as a login shell, which is the appropriate type of shell - if you instead tell iTerm to invoke a command to launch a shell, it won't be launched as a login shell in this situation [1].

[1]: Trying to get around that by using shell-specific options along with the command is not possible for all shells, and even when it is, often will not make that shell a true login shell in all respects (e.g. providing iTerm with a Command and using /bin/zsh --emulate sh --login will include l in the $- string, but will not make the first character of 0ドル a dash (-) character).

answered Nov 7, 2024 at 0:26
0

I don't understand what you mean by default here, but you can specifiy for each of you profiles the shell which is loaded initially, when you open a tab or window with the respective profile. In iTerm2: Open the preferences, go to profiles, select your profile (for instance Default), and in the preference tab labelled General, see the section called Command. From the dropdown box, you select Custom Shell, and then enter in the field the command for running your shell, for instance

/usr/local/bin/bash

or, if you want a login shell,

/usr/local/bin/bash -l

or whatever shell you want to have.

answered Nov 8, 2024 at 11:56
3
  • I would assume that a custom shell is exactly not the default shell the OP was looking for :-) Commented Nov 8, 2024 at 12:33
  • @nohillside : That's why I asked the OP to clarify the meaning of default shell in the context of terminal configuration. iTerm knows about profiles, and there is a profile called "Default". Note that the OP did not ask about changing the default shell in MacOS, but only for iTerm2. Commented Nov 8, 2024 at 15:04
  • If you need clarifications, add a comment beneath the question, don’t use answers for this. Anyway, the question was asked 10 years ago so the OP may not even be active here any longer Commented Nov 8, 2024 at 15:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.