Each shell can have its own feature set and language syntax, as well as a unique set of default environment variables. See Chapter 15 for more information about using the different shells included with Ubuntu.

At the command line, you can use the env or printenv commands to display these environment variables, like so:


GTK_RC_FILES=/etc/gtk/gtkrc:/home/andrew/.gtkrc-1.2-gnome2 USER=andrew

GNOME_KEYRING_SOCKET=/tmp/keyring-0eAV7D/socket SSH_AUTH_SOCK=/tmp/ssh-idRQhm5988/agent.5988 SESSION_MANAGER=local/optimus:/tmp/.ICE-unix/5988 USERNAME=andrew

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:\ /usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games DESKTOP SESSION=default







This abbreviated list shows a few common variables. These variables are set by configuration or resource files contained in the /etc, /etc/skel, or user /home directory. You can find default settings for bash, for example, in /etc/profile, /etc/bashrc, .bashrc, or .bash_profile files installed in your home directory. Read the man page for bash for details about using these configuration files.

One of the most important environment variables is $path, which defines the location of executable files. For example, if as a regular user, you try to use a command that is not located in your $path, such as the ifconfig command, you will see something like this:

$ ifconfig

-bash: ifconfig: command not found

However, you might know that ifconfig is definitely installed on your system, and you can verify this using the whereis command like so:

$ whereis ifconfig ifconfig: /sbin/ifconfig /usr/share/man/man8/ifconfig. 8 . gz

You can also run the command by typing its full pathname, or complete directory specification like this:

$ /sbin/ifconfig

As you can see in this example, the ifconfig command is indeed installed. What happened is that by default, the /sbin directory is not in your $path. One of the reasons for this is that commands under the /sbin directory are normally intended to be run only by root. You can add /sbin to your $path by editing the file .bash_profile in your home directory (if you use the bash shell by default, like most Linux users). Look for the following line:


You can then edit this file, perhaps using the vi editor (discussed in this chapter), to add the /sbin directory like so:


Save the file. The next time you log in, the /sbin directory will be in your $path. One way to use this change right away is to read in the new settings in .bash_profiie by using the bash shell's source command like so:

$ source .bash_profile

You will now be able to run ifconfig without the need to explicitly type its full pathname.

Some Linux commands also use environment variables, for example, to acquire configuration information (such as a communications program looking for a variable such as baud_rate, which might denote a default modem speed).

To experiment with the environment variables, you can modify the ps1 variable to manipulate the appearance of your shell prompt. If you are working with bash, you can use its built-in export command to change the shell prompt. For example, if your default shell prompt looks like

You can change its appearance by using the ps1 variable like this:

After you press Enter, you will see linux-gnu r00lz ->

Was this article helpful?

0 0

Post a comment