When zsh is set as a login shell on Mac OS X, when it is started by iTerm, zsh doesn't consider that it's being run as a login shell, although it's started as ‘-zsh’ (‘-’ is put as the first character of arg[0]) which is supposed to mean that it should start as a login shell.
So, when I set the login shell to bash, bash recognizes this first ‘-’ in $0 and runs as a login shell, but zsh doesn't, although it seems that it should.
Is there a way to either make zsh recognize the ‘-’ in the arg[0], or make iTerm run the shell with a --login command line argument?
In iTerm -> Preferences -> Profiles Tab -> General section set Command to: /bin/zsh --login
chsh -s $(which zsh)
You'll be prompted for your password, but once you update your settings any new iTerm/Terminal sessions you start on that machine will default to zsh.
Go to the Users & Groups pane of the System Preferences -> Select the User -> Click the lock to make changes (bottom left corner) -> right click the current user select Advanced options... -> Select the Login Shell: /bin/zsh and OK
The command to change the shell at startup is chsh -s <path_to_shell>
. The default shells in mac OS X are installed inside the bin
directory so if you want to change to the default zsh
then you would use the following
chsh -s /bin/zsh
If you're using different version of zsh
then you might have to add that version to /etc/shells
to avoid the nonstandard shell message. For example if you want home-brew's version of zsh
then you have to add /usr/local/bin/zsh
to the aforementioned file which you can do in one command sudo sh -c "echo '/usr/local/bin/zsh' >> /etc/shells"
and then run
chsh -s /usr/local/bin/zsh
Or if you want to do the whole thing in one command just copy and paste this if you have zsh already installed
sudo sh -c "echo '/usr/local/bin/zsh' >> /etc/shells" && chsh -s /usr/local/bin/zsh
Have you tried editing the shell entry in account settings.
Go to the Accounts preferences, unlock, and right-click on your user account for the Advanced Settings dialog. Your shell should be /bin/zsh, and you can edit that invocation appropriately (i.e. add the --login argument).
Use the login
utility to create a login shell. Assume that the user you want to log in has the username Alice and that zsh is installed in /opt/local/bin/zsh
(e.g., a more recent version installed via MacPorts). In iTerm 2, go to Preferences, Profiles, select the profile that you want to set up, and enter in Command:
login -pfq Alice /opt/local/bin/zsh
See man login
for more details on the options.