Bashrc guidelines

From SciNet Users Documentation
Jump to: navigation, search

The file .bashrc, located in your home directory, is read-in and executed whenever a bash script or bash shell is started. The exception is for login shells, in which case .bash_profile is started. The default .bash_profile calls .bashrc so that many scinet users never need to edit .bash_profile (the main exception is setting the PS1 variable, which you need to do in .bash_profile).

This means in particular that the file .bashrc is read in

  • when you log in
  • when you run compute jobs
  • when you run certain commands (such as mpirun, and python-script-called bash scripts).
  • at the end of a job, when copying output and error files.


To avoid difficulties, you are advised to follow these guidelines in .bashrc:

  • Sourcing /etc/bashrc is required for various SciNet routines to work!
  • Do not execute any commands that write to standard output, because that would breaks things like copying-out output files and scp. So for instance, no echo or module list.
  • Do not load any modules in your bashrc (or if you must, only very commonly-used modules).
  • If you're trying out different implementations or versions of a module (e.g. mpi), you should definitely not load them in the .bashrc, but explicitly on the command line before compiling and once more explicitly in your job script.

Default .bashrc and .bash_profile on Niagara

The default startup scripts provided by SciNet for Niagara are as follows. Certain things - like sourcing ~/.bashrc in ~/.bash_profile and /etc/bashrc in ~/.bashrc are required for various Niagara routines to work!


if [ -f /etc/bashrc ]; then
    . /etc/bashrc

function sbatch() { 
    command sbatch --export=NONE "$@"
export -f sbatch

alias passwd='echo "Please use the CCDB web portal to change passwords:"'

# Do not change the commands above! Customized functions and aliases can be entered below.

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias chmod='chmod -v'
alias more='/usr/bin/less'
alias df='/usr/bin/df -a -tgpfs -trootfs -h'


if [ -f ~/.bashrc ]; then
    . ~/.bashrc

# Do not change or remove the above lines.
# Additional variables and path settings can be set below.

export PS1='\u@\h:\w\$ '