Linux Bible. Christopher Negus
Чтение книги онлайн.
Читать онлайн книгу Linux Bible - Christopher Negus страница 44
OSTYPE
OSTYPE
value is either linux
or linux-gnu
, depending on the type of shell you are using. (Bash can run on other operating systems as well.)
PATH
/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:~/bin
. You need to type the full path or a relative path to a command that you want to run which is not in your PATH. For the root user, the value also includes /sbin
, /usr/sbin
, and /usr/local/sbin
.
PPID
PROMPT_COMMAND
PROMPT_COMMAND=date
lists the current date/time before the prompt appears.
PS1
PS2
, PS3
, and so on.
PWD
cd
command.
RANDOM
SECONDS
SHLVL
SHLVL
is 1
. Each time you start a new bash command (by, for example, using su
to become a new user, or by simply typing bash
), this number is incremented.
TMOUT
While you are in the shell, you can check which aliases are set by typing the alias
command. If you want to remove an alias, use unalias. (Remember that if the alias
is set in a configuration file, it will be set again when you open another shell.)
Exiting the shell
To exit the shell when you are finished, type exit or press Ctrl+D. If you go to the shell from a Terminal window and you are using the original shell from that window, exiting causes the Terminal window to close. If you are at a virtual console, the shell exits and returns you to a login prompt.
If you have multiple shells open from the same shell session, exiting a shell simply returns you to the shell that launched the current shell. For example, the su
command opens a shell as a new user. Exiting from that shell simply returns you to the original shell.
Creating Your Shell Environment
You can tune your shell to help you work more efficiently. You can set aliases to create shortcuts to your favorite command lines and environment variables to store bits of information. By adding those settings to shell configuration files, you can have the settings available every time you open a shell.
Configuring your shell
Several configuration files support how your shell behaves. Some of the files are executed for every user and every shell, whereas others are specific to the user who creates the configuration file. Table 3.6 shows the files that are of interest to anyone using the bash shell in Linux. (Notice the use of ~
in the filenames to indicate that the file is located in each user's home directory.)
To change the /etc/profile
or /etc/bashrc
files, you must be the root user. It is better to create an /etc/profile.d/custom.sh
file to add system-wide settings instead of editing those files directly, however. Users can change the information in the $HOME/.bash_profile
, $HOME/.bashrc
, and $HOME/.bash_logout
files in their own home directories.
TABLE 3.6 Bash Configuration Files
File | Description |
/etc/profile
|
This sets up user environment information for every user. It is executed when you first log in. This file provides values for your path in addition to setting environment variables for such things as the location of your mailbox and the size of your history files. Finally, /etc/profile gathers shell settings from configuration files in the /etc/profile.d directory.
|
/etc/bashrc
|
This executes for every user who runs the bash shell each time a bash shell is opened. It sets the default prompt and may add one or more aliases. Values in this file can be overridden by information in each user's ~/.bashrc file.
|
~/.bash_profile
|
This is used by each user to enter information that is specific to his or her use of the shell. It is executed only once—when the user logs in. By default, it sets a few environment variables and executes the user's .bashrc file. This is a good place to add environment variables because, once set, they are inherited by future shells.
|
~/.bashrc
|
This contains the information that is specific to your bash shells. It is read when you log in and also each time you open a new bash shell. This is the best location to add aliases so that your shell picks them up. |
~/.bash_logout
|
This executes each time you log out (exit the last bash shell). |
Until you learn to use the vi
editor, described in Chapter 5, “Working with Text Files,” you can use a simple editor called nano
to edit plain-text files. For example, enter the following to edit and add stuff to