12. Customising the shell

This section is optional for those who want to make their terminal environment a bit more friendly — ask the demonstrators for more details if you get this far and have the interest.

Setting your PATH as you learned earlier will only last until you close the terminal. You don’t want to have to do that every time you open a shell session! For this, you can add shell snippets to dot files in your home directory HOME. Files that start with a dot (kbd{.}) are usually hidden when you use ls, but the -a switch will reveal them. Try:

$ ls -a $HOME

The important ones for customising bash are .bash_profile and .bashrc. You can read these into the shell (rather than executing them: that would run in a child process and not affect your shell session) using the source or . command:

$ source ~/.bashrc

or

$ . ~/.bashrc

You can also run reset to reset your shell which will automatically re-read the setup files.

Have a look at the contents of the .bashrc file using less or cat (or gedit).

Aliases can be used to override commands — they are a kind of extra layer in command execution before the PATH gets read. Here’s how to set an alias:

$ alias ls="ls -l"

That sets an alias which changes ls to use the long listing mode by default. Try ls now.

To access a command and guarantee that you aren’t using an alias, you can prefix the command with command:

$ command ls

You can get rid of this rather annoying alias with unalias ls!

Shell functions are like aliases but are a bit more powerful: the main difference is that they can take arguments. Ask for more information.