Terminal.app: changing shell behavior problem

bashcommand lineterminal

I'm having problems setting Terminal.app's default shell. It appears to work using a command line utility which sets the shell for the account, however not in Terminal.app's dialog which is for each session. I find that if I set the shell system with with 'chsh', the $SHELL variable in Terminal.app correctly reflects the shell. If I change the shell in Terminal.app only, $SHELL does not correctly reflect the shell, however the shell appears to be the correct shell running. I tried this on a temp account to rule out other interactions and it has the same behavior.

Here is a use case:
When I run in Terminal.app:

$ chsh -s /bin/ksh

and invoke Terminal.app, the shell is correctly changed:

$ echo $SHELL
/bin/ksh

The problem is if try similar through Terminal.app->Preferences->General->Shells open with->Command->/bin/ksh

$ echo $SHELL
/bin/bash

Yet when I try command completions with TAB, it reflects ksh behavior.

Therefore, my suspicion is there is something overriding the SHELL environment variable where it is always SHELL=/bin/bash, despite the shell being different than that.

Does anyone know if Apple has a bug here?

Best Answer

The following information is taken from

on Unix & Linux, which applies to macOS as well.

You are running the Korn shell if the Terminal preference is set to /bin/ksh. The output

$ echo $SHELL
/bin/bash

is misleading because the SHELL variable is set by the login process to

The user's shell, as specified by the password database.

(On macOS it is a user database and not the /etc/passwd file as on Linux, where that information is stored, but that does not matter.)

You can type

$ echo $0
-ksh

or

$ echo $KSH_VERSION
Version AJM 93u+ 2012-08-01

to verify that you are running the Korn shell.

Setting the shell via

$ chsh -s /bin/ksh

sets the login shell in the user database, and then SHELL is set accordingly:

$ echo $SHELL
/bin/ksh