Share this post
FaceBook  Twitter  
Contents[Hide]

1. Introduction

In order to make your working environment as comfortable as possible, one place to start with is the shell. It's usually recommended that you start with your (user-) specific settings, as found in your home directory, then, if it's a single user machine, make said settings global. If you think the details are rather scarce within this article, don't worry: details pertaining to environment variables and their uses will come later in another article.

2. First look at customizing your shell

We feel compelled to warn you again: the default shell used throughout these articles is Bash 4.x, with exceptions noted as such if necessary. So, if you're using another shell, consult its respective manual page for details on what to alter and how to edit configuration files.

2.1. User-specific files

The files that allow per-user configuration, as opposed to global configuration, are ~/.bash_profile and ~/.bashrc. However, for sh compatibility (the original Bourne shell), and for interoperability with other Bourne-compliant shells, you might see a ~/.profile in there as well. The idea is: ~/bash_profile is Bash-only, while settings in ~/.profile will be shared amongst other sh-compatible shells. So you might wonder: why two configuration files? Well, because Bash can be a login shell or simply an interactive shell, and most people would want those two seprarated, settings-wise. So, ~/.bash_profile is for login shells (again, user-specific), while ~/.bashrc is for the ordinary, average interactive shells.

2.2. Global files

The system-wide equivalents of the two aforementioned files are /etc/profile for login shells and /etc/bashrc for aliases and settings. Here's how the file's intro looks like on my system:

# System wide functions and aliases
# Environment stuff goes in /etc/profile
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

Speaking of environment stuff, let's go further, to...

3. Environment variables

These are variables, just like in a programming languages, that hold different values regarding your shell, affecting the behavior of running processes. Thus, some are process-specific, others are user-specific, yet others are system-specific. While the concept comes from Unix, OS/2 and Windows also have the concept, even though the naming might be different. In a previous article, we have seen that in order to check what is our default shell, one method is to type echo $SHELL. This is an environment variable, user-specific of course, that tells us what is our default shell. Variables are first defined without the dollar sign, then used with it, so that the shell knows it's a variable, environment or not (see the section on shell programming). If you want to see all the environment variables in place at that moment, just type env. If you want to change a variable, use export: SHELL=/bin/tcsh; export SHELL or, even simpler, in one step: export SHELL=/bin/tcsh. Please note the lack of the dollar sign when defining a variable. Deleting an environment variable is made through the unset command, using the variable as an argumemt, without the dollar sign. For example, unset $SHELL.

4. Exercises

1. Read the Bash manual page and try to figure out, using the FILES section, why it has so many config files.

2. Why couldn't it be only a ~/.profile for sh and bash as well?

3. Define the differences between a login and a non-login shell

4. Read all four files on your system (global and user-specific) and try to explain why the $PATH is different between root and other users.

5. Using the output of env, try to determine what variables are user-specific and what are global. Try altering some of them and see what happens.

6. One of the suggested commands in this article might be detrimental to the good operation of your computer. Which is it, why, what do you think it would happen and how would you repair the problem?

Partners

Who are we?

LinuxCareer.com is not affiliated with any local or international company, nor is it a recruitment or employment agency. We specialise in Linux based careers and closely related Information Technology fields by providing careers advice and latest employment opportunities.

JOIN LINUXCAREER

You can also get involved in the LinuxCareer project by participating on our FORUM or SUBMITTING A LINUX ARTICLE. We offer a range of privileges to our authors and good company.