bash Configuration

All of the Salish Sea MEOPAR documentation assumes that you are using the bash shell. You can check which shell you are using with:

echo $SHELL

If the result is not something like /bin/bash you may be able to start bash with:

bash

You may want to request that your IT support change your default shell to bash to avoid having to start bash every time that you open a new shell window/tab. For the Waterhome workstations and salish you can open a ticket with the request on the EOAS Compstaff Helpdesk system. On Westgrid, send an email request to support@westgrid.ca.

If you are new to bash or the Linux command line the copy of “The Linux Command Line” by William E. Shotts, Jr. in the Waterhole will help you, as will this Unix Shell Quick Reference page from Software Carpentry.

.bashrc Snippets

bash executes the commands in $HOME/.bashrc every time a new shell window/tab is opened. If you do not have a $HOME/.bashrc file you can create it using your favourite editor.

The rest of this section described various snippets of bash code that you may want to include in your $HOME/.bashrc file.

To shorten your prompt so that it shows just the name of the machine that you are on and the directory that you are currently in instead of the whole path to that directory use:

PS1="\h:\W$ "

To force programs and commands that want to display output page by page to use less as their pager use:

export PAGER=less

To force less to allow control sequences that change the colour of output to work use:

export LESS=-R

If you are not a fan of the vi editor you can set the EDITOR and VISUAL environment variables to the command for your favourite editor and export them. For emacs use:

export EDITOR=emacs
export VISUAL=emacs

The $HOME/bin/ directory is the conventional place keep your own scripts so it is a good idea to add that directory to the end of your PATH:

export PATH=$PATH:$HOME/bin

The $HOME/.local/bin/ directory is where Python scripts installed via the --user option are stored so it should be near the beginning of your PATH:

export PATH=$HOME/.local/bin:$PATH

If you are using the Anaconda Python distribution you should add its bin/ directory to the beginning of your PATH:

export PATH=$HOME/anaconda3/bin:$PATH

Aliases allow you to run commands with different names or with particular option flags set.

To make the ls command use different colours for regular files, executable files, directories, symbolic links, etc., and post-fix characters to indicate those file types use:

alias ls="ls --color=auto -F"

To make la include hidden files in file listings use:

alias la="ls -a"

To make ll display long file listings that include permissions, owner and group, and last modification date/time, and also include hidden files use:

alias ll="ls -al"

Aliases are cumulative, so if the above three aliases are all defined in the order shown, ls, la, and ll will all produce coloured, post-fixed file listings.

To always be prompted to confirm file removals use:

alias rm="rm -i"

Some things cannot be easily accomplished with aliases and so bash also provides a way of writing functions. One good use for bash functions is creating commands that change directories for you to particular locations without having to type long paths. For example:

go_results() {
    cd /ocean/$USER/MEOPAR/SalishSea/results;
}

creates the go_results command that will cd from wherever you are to the directory where your Salish Sea NEMO model run results are stored.

.bash_profile

To ensure that .bashrc is executed when you login via ssh create a file $HOME/.bash_profile with the following lines:

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

Loading Modules on HPC Clusters

When working on ComputeCanada or Westgrid clusters the module command must be used to load several software components required to compile, run, and work with the results of NEMO. The required modules vary from machine to machine:

  • On cedar and graham the module load commands you should include in your $HOME/.bashrc are:

    module load python/3.7.0
    module load netcdf-fortran-mpi/4.4.4
    
  • On orcinus the module load commands you should include in your $HOME/.bashrc are:

    module load python
    module load intel
    module load intel/14.0/netcdf-4.3.3.1_mpi
    module load intel/14.0/netcdf-fortran-4.4.0_mpi
    module load intel/14.0/hdf5-1.8.15p1_mpi
    module load intel/14.0/nco-4.5.2
    

You can inspect the collection of modules that are loaded with the module list command; for example, on cedar:

module list
Currently Loaded Modules:
  1) nixpkgs/16.09   (S)   4) ifort/.2016.4.258 (H)      7) openmpi/2.1.1 (m)  10) hdf5-mpi/1.8.18          (io)
  2) icc/.2016.4.258 (H)   5) intel/2016.4      (t)      8) StdEnv/2016.4 (S)  11) netcdf-mpi/4.4.1.1       (io)
  3) gcccore/.5.4.0  (H)   6) imkl/11.3.4.258   (math)   9) python/3.7.0  (t)  12) netcdf-fortran-mpi/4.4.4 (io)

  Where:
   S:     Module is Sticky, requires --force to unload or purge
   m:     MPI implementations / Implémentations MPI
   math:  Mathematical libraries / Bibliothèques mathématiques
   io:    Input/output software / Logiciel d'écriture/lecture
   t:     Tools for development / Outils de développement
   H:                Hidden Module