bash vs tcsh on the RC clusters
Using bash and tcsh on the RC clusters:
NOTE: to tcsh users, adding a .tcshrc to your home folder will prevent the usual RC environment from being created. Please put all startup commands in .cshrc or alternatively in .cshrc.$PLATFORM. See the modules page for more information about platform/cluster specific .cshrc files.
Changing to bash from tcsh:
We are moving to bash as the default shell for all new user accounts. Users who currently use tcsh may request a change to bash by submitting a support ticket.
This page summarizes the most important differences between tcsh and bash, with emphasis on interactive use, startup files, SLURM jobs, environment modules, Conda, and shell scripting.
To check which shell you are currently running, use the command echo $0 at the command prompt:
[1 ewalter@bora ~ ]$echo $0
-bash
The output -bash means that you are running bash and the '-' sign means it is a login shell.
Overview
A shell is the command-line program that reads and runs the commands you type.
Many common commands work the same in both tcsh and bash, including:
- cd
- ls
- pwd
- cp
- mv
- rm
- mkdir
The biggest differences appear when you work with:
- shell startup files
- environment variables
- variables and aliases
- SLURM job scripts
- environment modules (see the environmental modules page for more info)
- scripting syntax (see this on bash scripting)
Startup files
One of the most important changes when moving from tcsh to bash is how shell startup files work.
tcsh startup files
Users commonly work with:
~/.cshrc
~/.login
Typical usage:
~/.cshrc for aliases, prompt settings, shell behavior, and interactive setup
~/.login for login-time initialization
bash startup files
Users commonly work with:
~/.bashrc
~/.bashrc_profile
Typical usage:
~/.bashrc for aliases, functions, prompt settings, and interactive shell behavior
~/.bash_profile for login-time setup
How .bash_profile and .bashrc work together
In bash, ~/.bash_profile is typically used for login-shell setup.
A common pattern is for ~/.bash_profile to source ~/.bashrc, so that login shells also pick up the user’s usual interactive shell settings:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
This allows settings in ~/.bashrc , such as aliases, functions, prompt customization, and other interactive shell behavior, to be available in login shells as well.
It is important to note that this does not mean ~/.bash_profile is used for non-interactive shells. In general:
-
~/.bash_profile is read for login shells
- ~/.bashrc is read for interactive non-login shells
- non-interactive bash shells, such as shell scripts, do not normally read either file automatically, but do inherit your current environment
Practical guidance
When moving from tcsh to bash, a good rule of thumb is:
- put aliases, prompt settings, functions, and interactive customizations in ~/.bashrc
-
put login-time setup in ~/.bash_profile
-
have ~/.bash_profile source ~/.bashrc
Environment variables
Setting environment variables is different in tcsh and bash.
setenv PROJECT myproject
echo $PROJECT
Notes: in bash, do not put spaces around =
Shell variables
Aliases:
tcsh:
alias ll 'ls -l'
bash:
ll='ls -l'
Running SLURM job bash scripts under a tcsh login environment:
If you have bash as your default shell, running either tcsh or bash based scripts will work correctly.
However, if you use tcsh by default and run a bash script, you must add the following to your batch script right after any SLURM declarations:
source /usr/local/etc/sciclone.bashrc
Example:
#!/bin/bash#SBATCH --job-name=test1#SBATCH --nodes=1 --ntasks-per-node 1#SBATCH --time=30##SBATCH --mail-user=ejwalt@wm.edu##SBATCH --mail-type=allsource /usr/local/etc/sciclone.bashrc./a.out > OUTSourcing the sciclone.bashrc (or ches.bashrc on the VIMS clusters) ensures that the proper bash environment is set up since your default shell tcsh doesn't permit the this. If your default is bash, however, it can set up the tcsh environment with no problems.