Posts Tagged ‘csh’
Using exec /bin/bash in .cshrc
By chys on February 6th, 2009I don’t like tcsh, which is the login shell here. I cannot make bash the default with ypchsh – the administrator does not allow this change. I’m also tired of typing exec bash every time, so I have to experiment with adding exec /bin/bash to ~/.cshrc. This is the code I’m currently using which seems to be working well:
if ($?prompt && "$0" =~ -* ) then exec /bin/bash endif
The first condition $?prompt determines whether this is an interactive shell. This is necessary, otherwise various utilities including scp can fail in strange ways. (scp needs to execute commands using the login shell remotely.)
The second one, "$0" =~ -* excludes non-login instances. So I can type tcsh to explicitly switch to tcsh. This is useful if someone more familiar with the C shell is temporarily using my account.
This probably is not the best way to determine whether the shell is a login, but well, it works in all cases I can imagine… (Similarly, we can use [[ "$0" == -* ]] in bash, but it seems people prefer [[ $- == *i* ]].)
