Changing shells in Terminal

Joined
Nov 4, 2011
Messages
4
Reaction score
0
Points
1
Hi All,

I have Terminal 2.2.1. It appears that I cannot change from bash shell to tsch on the fly. I find this rather surprising:

>$ echo $SHELL
/bin/bash
>$ /bin/tcsh
>% echo $SHELL
/bin/bash

Can anyone explain this behavior to me?

Thanks,
Will
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
mikeMBP:~ mike$ echo $SHELL
/bin/bash
mikeMBP:~ mike$ echo $0
-bash
mikeMBP:~ mike$ exec /bin/tcsh
[mikeMBP:~] mike% echo $0
/bin/tcsh
[mikeMBP:~] mike% echo $SHELL
/bin/bash
[mikeMBP:~] mike%

Note that after the exec, the prompt changed (and it did in your example too)? The change from $ to %? That's a dead giveaway. $ is a bash shell prompt, % is a c shell prompt. $SHELL still echos /bin/bash though.

A better example is this. The print command does not exist in bash, but exists in korn.

mikeMBP:~ mike$ print "korn shell"
-bash: print: command not found
mikeMBP:~ mike$ exec /bin/ksh
$ print "korn shell"
korn shell
$ Echo $0
/bin/ksh
$ foo
/bin/ksh: foo: not found
$ echo $SHELL
/bin/bash
$

if we take a look at the environment variables... we see that SHELL is defined as /bin/bash. You'd have to export a new variable to change that.

mikeMBP:etc mike$ env
TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
CLICOLOR=1
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
I have Terminal 2.2.1. It appears that I cannot change from bash shell to tsch on the fly.
As Mike noted, you did change shells but note that the env. variable doesn't change with it. If you want to change that at the same time, you can execute the following:
Code:
export SHELL=/bin/tcsh ; /bin/tcsh
You have to export the new value first as noted in the command above. Otherwise, it won't take since tcsh will have already launched.

You'll note here that when you do this, the value of $SHELL remains /bin/tcsh when you exit tcsh so you'll have to export /bin/bash if you want $SHELL to change back.
 
OP
W
Joined
Nov 4, 2011
Messages
4
Reaction score
0
Points
1
Thanks

Thanks vansmith and Dysfunction!

The $SHELL variable not changing is strange to my linux background, but I appreciate the help :)

Will
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
This behaviors identical on the linux boxes I work on. Might be a distribution thing though.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top