Bashrc guidelines

From SciNet Users Documentation
Revision as of 17:38, 15 May 2018 by Rzon (talk | contribs) (Created page with "The file <tt>.bashrc</tt>, 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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to 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 python scripts called bash scripts).

Guidelines

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 command 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!


.bashrc

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

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

alias passwd='echo "Please use the CCDB web portal to change passwords: https://ccdb.computecanada.ca"'

# 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'

.bash_profile

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

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

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