A friend recently mentioned his hatred of ksh and inability to change his default shell because he is not root and root will not make the change. I concur, ksh is turrible, that needs fixed. Here’s a little trick for anyone else who has this issue. Let’s say you want to use bash and the shell forced upon you is ksh. The Korn shell uses .profile to set up your environment when you log in, so append these two lines to your profile:
# run bash damnit [ ! "`which bash | egrep "^no"`" ] && [ -z $BASH ] && exec bash --login
We look for the output of which bash and ensure it does not say no bash in …, and if that file is non-zero, we exec bash as a login shell. You can read man exec for details on specifically how it works in a given shell, but it essentially replaces the running shell with the new command. If the first two checks are positive, then bash is executed and replaced the ksh process. Once the files are added to your profile, log in again in a new session. Voila, you now have a bash login shell!
rnelson0@dumbserver ~ $ ps -ef | grep bash rnelson0 5927 5298 0 19:56:42 pts/1 0:00 grep bash rnelson0 5298 5292 0 19:47:48 pts/1 0:00 bash --login
If you’re forced to use a different shell, you may need to locate a different profile file. If you want to use a different shell, just sub out bash for the name of your preferred shell. Enjoy!
At the risk of bikeshedding…
which bash > /dev/null && [ -z “$BASH” ] && exec bash –login
🙂
The profile command I have goes back to the days of using HP-UX – so there may have been some variance in exit codes based on OS, or I just cribbed from someone else’s style. Others add `&& tty` in there to make sure non-interactive shells do not break. Lots of ways to skin this cat!
Yeah, the “which” command on OSX doesn’t produce any output if the command is not found so the grep wouldn’t work.
Ah, I love the smell of unix!
This is a useful summary of how to find commands cross-platform: http://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then
It seems to suggest “command -v” is the favoured approach.
command -v bash > /dev/null && [ -z “$BASH” ] && exec bash –login