Configuration of the User Environment

The Shell and Environment

Whenever a user logs in by ssh or starts a `terminal emulator' or `console' or `command line' (oft-used synonyms), there is a shell program running to interpret the commands. A Unix shell is simply a user-space program with no special privilege, whose language is designed to make it easy to run commands, provide arguments to commands, chain commands together, get commands read and write files, make loops and conditionals, etc.

The shell's purpose is described more on the scripting page, which links to tutorials on the syntax. The following paragraphs are not so much about the shell itself as its calling of other programs. The most compact reference on the shell is pretty surely its own manual page (`man bash' or `info bash'), but this isn't a very friendly introduction to a few basic uses!

Temporary and Permanent Changes

The following aliases, environment variables, etc. can be run interactively, typing them into the shell, and they will affect the remainder of that session. By putting the same commands in the configuration file, they will affect all subsequent sessions (but not the current session unless the configuration is manually `re-sourced').

The main user-configuration file to consider, for the GNU shell (`bash') that is the default on our systems, is ~/.bashrc (bash run-control, a hidden file, as shown by the initial dot in its name -- remember that the tilde symbol denotes `home directory' of the current user). This initially should contain just a few lines that include the system-wide configuration. This should be left in, otherwise many programs and libraries won't be detected. It is best to be at the top, so that later changes will override the system settings with the user's settings.

To make the current shell see changes to ~/.bashrc, run `source ~/.bashrc'. The dot symbol is an alternative to the word `source': `. ~/.bashrc'. Note: sourcing the ~/.bashrc file should not yield any output to the screen, for example from some command that generates text: if this happens, there may be problems with running commands remotely over ssh.

Aliases

Aliases can be included to shorten often-used commands, e.g. 'alias ll="ls -l"' provides the command ll that will do a long listing of files; this one is already set on our systems -- see the bottom of the global /etc/bash/bashrc .

Environment Variables

Shell variables are set by `variable_name='some string''. The quotation marks are only needed if there are spaces or other `shell metacharacters' in the assigned string. When the variable_name is subsequently used, prefixed with a dollar sign $variable_name, it will be replaced by its contents when that line of shell is run. By the command `export variable_name', a variable can be exported to child processes, and convey information about for example the desired language, the user's home directory, the temporary directory, or the directories to search for executables, libraries and manual pages. The command `env' shows the currently set variables in the `environment'.

Other programs' configuration

The only place where programs can store user-specific configuration is in that user's home directory (they could try, say, /tmp, but then it could be expected to disappear). This is almost always done by making either a hidden file or directory directly inside the user's home. Listing the home directory with all hidden files (`ls -a') will reveal quite a few such configuration files. Sometimes, it can be convenient to modify these files, to copy ones from other systems where everything is nicely set up already, or to delete or move them in order to see if a problem with a program is simply because of old or corrupted configuration.

The Art of Unix Programming is an interesting book that is also freely available on the web. It covers a lot of aspects of choice of file-formats, program configuration, approaches to user-interaction, and different ways to do programming tasks, as well as matters of software development models (open vs. closed, etc.).


Page started: 2007-11-xx
Last change: 2007-11-08