Issue:
How can I change the shell that X11 windows (e.g., xterm) inherit from X11.app? I want to use tcsh, but X11 insists on bash. This issue and solution are presented as a slightly edited (I fixed my typos and added a few comments and links) version of an email conversation I had with a user of this site (code name: “DSD”), who asked for help resolving this X11 behavior.
DSD:
I know you think I'm misguided [DSD is referring to my tip on changing the default shell in OS X – DWH], but I've used csh and tcsh for so long I don't/can't adapt to bash. My problem is that, on my new MacBook Pro, I cannot get the X11 application to recognize that I want /bin/tcsh as my default shell. (Yes, /bin/tcsh is present in /etc/shells.)
I tried using /usr/bin/chsh (which I've used since Mac OS X came out), but the application returns with the message “chsh: no changes made”. And sure enough, when I log out/in or reboot and relaunch X11, I get the “bash-3.2” prompt and echo $SHELL = /bin/bash.
Your site came up on top when I googled my problem, and I followed your directions using the System Preferences utility. The advanced options window says that my default shell *is* /bin/tcsh, and when I launch the Terminal application I'm in the /bin/tcsh shell. But, X11 does not appear to recognize this.
Do you have any idea what is happening?
Thanks and regards,
DSD
Solution:
DWH:
hi DSD – What version of X11 do you have? You can find out by selecting “About X11” in the “X11” menu of the X11 application. I ask because X11 2.3.2 and earlier inherit the bash shell automatically, whereas 2.3.3 and later inherit whatever shell you are using [See this web page – DWH]. So that might be the simplest explanation.
In X11 2.3.3+, there is a shell script located at
/Applications/Utilities/X11.app/Contents/MacOS/X11
which is executed when X11 starts, and causes X11 to inherit your shell. I've attached the shell script [see below – DWH] – you might try inserting it at the right place in your X11.app (see path above). I don't see any reason why it wouldn't work with an earlier version of X11 also (but be careful to save a backup copy of the existing X11 startup script before you try this, in case you need to go back to it).
/Applications/Utilities/X11.app/Contents/MacOS/X11:
#!/bin/bash
set "$(dirname "$0")"/X11.bin "${@}"
if [ -x ~/.x11run ]; then
exec ~/.x11run "${@}"
fi
case $(basename "${SHELL}") in
bash) exec -l "${SHELL}" --login -c 'exec "${@}"' - "${@}" ;;
ksh|sh|zsh) exec -l "${SHELL}" -c 'exec "${@}"' - "${@}" ;;
csh|tcsh) exec -l "${SHELL}" -c 'exec $argv:q' "${@}" ;;
es|rc) exec -l "${SHELL}" -l -c 'exec $*' "${@}" ;;
*) exec "${@}" ;;
esac
DSD:
Thanks for the quick reply! Here's what it comes back with:
XQuartz 2.3.5 (xorg-server 1.4.2-apple53) [That's up to date for OS X 10.6.3 – DWH]
I'll check out the shell script angle...
The X11 file you attached is identical to the one at the location above.
Don't know what to do next!
DWH:
Well, that would have been too easy. So, a few things to try:
1) Do you have .tcshrc or .xinitrc files in your home directory? If so, change their names to .tcshrc~ and .xinitrc~. While you're at it, make sure you don't have any stray .bashrc or .bash_profile files either. Log out and back in, start X11 in your usual way. Did it work? If so, then something is broken in one or more of those files. If not, go on to #2...
2) If not, then change the names of the files from step #1 back to their originals. Do you have a directory in your home directory called .MacOSX? Type
ls -a ~
to check for this. If so, then
ls ~/.MacOSX
If it lists a file called environment.plist, then
open ~/.MacOSX/environment.plist
Opening this file will require that you have the Property List Editor installed, which comes with the OS X Developer tools. If you don't have the Property List Editor and/or don't want to install it, then proceed to the next step. If you do not have the environment.plist file, then also proceed to the next step.
If you do have the Property List Editor, and it opens the environment.plist file, then you want to have a line in there under the “Root” menu that defines “SHELL” as “/bin/tcsh” – see attached screen grab [See below – DWH]. Add this line, save, log out and back in.
3) If item #2 isn't working for you, then make a backup of your existing environment.plist (if it exists), and place the attached environment.plist [See below – DWH] into your ~/.MacOSX directory. Log out and back in. This file contains only a single definition: setting SHELL to be /bin/tcsh, as described in item #2.
What is happening is that every time you login, the first thing OS X does is look for the ~/.MacOSX/environment.plist file. If it exists, then the OS reads it, and passes the environment variable definitions on to ALL other applications that are started. I tested this by disabling my ~/.bashrc and ~/.bash_profile files (which normally make settings for the bash shell when I login), and creating ~/.MacOSX with the attached environment.plist file in it. I logged out and back in, and even though my default shell (i.e., in System Preferences) is still set to bash, when I start X11, the xterm windows open in the tcsh shell.
Good luck!

~/.MacOSX/environment.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SHELL</key>
<string>/bin/tcsh</string>
</dict>
</plist>
DSD:
You did it! Number 3 worked. No. 1 had no effect, I didn't have that directory (~/.MacOSX/), so I created it and copied the plist file you sent into that directory.
Thanks for all your help on this one.
DWH:
Great, I'm glad that worked for you.
OS Version Compatibility: Lion, Snow Leopard, Leopard
Update Status: 02 February 2010
|