So, based on one of your comments, you really want to know how to determine which shell you are using; you suggested that $0
was the solution, and asked about it, but as you saw, $0
will not reliably tell you what you need to know.
If you use bash, then several unexposed variables will be set, including $BASH_VERSION
. If you use tcsh, then the shell variables $tcsh
and $version
will be set. (Note that $version
is an overly generic name, I ran into problems when some kind of system-run script sets it and compresses a tcsh-specific variable, but $tcsh
should be reliable.)
The real problem is that the syntax of bash and tcsh is basically incompatible. Perhaps you can write a script that can be executed when called (via .
Or source
) from tcsh or bash, but that would be complicated and ugly.
The usual approach is to have separate installation files, one for each shell you use. For example, if you use bash, you can run
. ~/setup.bash
or
. ~/setup.sh
and if you use tcsh, you can run
source ~/setup.tcsh
or
source ~/setup.csh
Versions of .sh
or .csh
refer to the ancestors of both shells; it makes sense to use these suffixes if you are not using any bash-specific or tcsh-specific functions.
But this requires knowing which shell you are using.
Perhaps you could create an alias in your .cshrc
, .tcshrc, or
.login , and an alias or function in your
.profile ,
.bash_profile , or
.bashrc`, which is called depending on what script you need.
Or, if you want to configure it every time you log in or every time you launch a new interactive shell, you can put the commands directly into the corresponding shell launch files. Of course, the teams will be different for tcsh
vs. bash
.