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:
- Changed "command" as
/bin/zshin iTerm's configuration window. - Executed
chshto change the shell to/bin/zsh. - 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
8 Answers 8
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/".
-
Buddy of mine had the same issue w/ intelliJ.slm– slm2020年09月22日 15:03:33 +00:00Commented 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!Stephen Hosking– Stephen Hosking2021年03月21日 11:22:31 +00:00Commented Mar 21, 2021 at 11:22
-
1@StephenHosking with iTerm active, do
CMD + ,to reach Preferencessidcha– sidcha2021年05月12日 21:43:49 +00:00Commented May 12, 2021 at 21:43 -
Remove the
/at the end of youriTermpreferences shell path, because it might cause errors in shell scripts.athena– athena2021年08月07日 09:11:45 +00:00Commented Aug 7, 2021 at 9:11
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.
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.
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.
-
I tried
chshwith no args. Still no luck. The variable doesn't change. In fact, when the editor was loaded, it showed/bin/zsh.melvynkim– melvynkim2014年05月25日 02:54:54 +00:00Commented 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.movNevin Williams– Nevin Williams2014年05月25日 04:09:26 +00:00Commented 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
$SHELLon iTerm. Please refer to my answer for details.. Thanks!melvynkim– melvynkim2014年05月26日 18:40:16 +00:00Commented May 26, 2014 at 18:40
Try executing the command: chsh -s /bin/zsh from the default Mac terminal.
-
1What does this do differently from the OP?JMY1000– JMY10002017年02月07日 16:12:48 +00:00Commented 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.mohitmayank– mohitmayank2017年02月10日 02:37:27 +00:00Commented Feb 10, 2017 at 2:37
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.
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
- change your macOS user default shell to the shell you want to use, and then
- 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- as described e.g. in https://stackoverflow.com/a/23072501/1562596
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).
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.
-
I would assume that a custom shell is exactly not the default shell the OP was looking for :-)2024年11月08日 12:33:47 +00:00Commented 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.user1934428– user19344282024年11月08日 15:04:26 +00:00Commented 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 longer2024年11月08日 15:20:00 +00:00Commented Nov 8, 2024 at 15:20
/etc/shells? The manual states that if the shell you specify is not in that file, it isn't considered a standard shell.iTerm. The variable is built at login shell from the default shell used byiTerm.SHELLset to zsh, do it in your ~/.zshenv:export SHELL=/bin/zsh, or betterexport SHELL==zshif you want to play around with different zsh versions.SHELLis not a particular zsh variable, but you can set it to any value you want.