Saturday, February 09, 2002

Check your Settings

As mentioned earlier, the shell is the command between you and the Linux kernel. I also said I will explain things for the bash shell, since it is the one I know better.

There are several configuration files for bash (do not worry if you don't understand all terms in this list):

  1. /etc/profile: system configuration for logging shells
  2. /etc/bash.bashrc: system configuration for interactive shells
  3. /etc/bash_logout: system configuration to be executed when you log out
  4. ~/.bash_profile: personal configuration for logging shells
  5. ~/.bashrc: personal configuration for interactive shells
  6. ~/.bash_logout: personal configuration for logging out

An interactive shell is when, for example, you execute a command in a remote machine via ssh (more on connections to other machines in other posts). On the other hand, a logging shell is what you get when you log on in the system.

The system configuration files can be changed only by the super user, root, so I will not talk about them here. The personal configuration files allow you to change the settings done by the system. There are plenty of variables that you can put in your configuration files; I will explain some below, but first a note about interactive/loggging configurations. In my account the files ~/.bashrc and ~/.bash_profile are identical, so I do not worry about missing something in a logging shell, or in an interactive one. I do not know if it is a good practice, but I find it convenient.

Now about some of the variables you can set up. I will explain what they are, and I will give examples of how the configuration file should look like.

How to find your settings

If you want to know the current settings of your shell you can use the set or env
commands.

EDITOR

Many commands require to call an editor, which is normally set up in the variable EDITOR of your shell. The system might have a default editor, for example in mine is nano. If you do not like it you can change to something else, say emacs, with this configuration line:


export EDITOR=emacs

Be sure you can find emacs in your path; test it by just typing emacs in your shell and see it comes.

How to update changes

After you have editing your configuration file you can make the changes active by either logging out and in, or just with this:


source ~/.bashrc

Here, obviously, I assumed you modified your ~/.bashrc file.

HISTORY

This history keeps a record of the last commands you have typed in the shell. Usually you can "recover" them with the up/down arrows: pressing them will show the different commands you have executed in the shell, perhaps saving you the time of typing them again. The following configuration line will keep 100 commands in the history file (~/.bash_history):


set history=100

For personal experience I know that more than 100 commands is not very useful, but you might want to keep the last 500, 1000, whatever. I do not know the limit.

PATH

This is a set of directories where the shell will look for commands. The different directories should be separated by colons (:). In the example below I have broken the line in several shorter lines so it displays nicely, but you should put a single, long line in your configuration file:


export PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/bin:
/usr/share/bin:/usr/local/share/bin:~/bin

The last directory, ~/bin, means a directory called bin in your home directory (the tilde ~ stands for your home directory). I have one such directory where I keep all programs that I compile myself. You can add one more directory, ., dot, which means the current directory from which you execute the command (for those that have used Linux, adding dot will allow you to execute a.out instead of ./a.out).