bash (Bourne Again Shell) customizations most useful bash: PATH, aliases, prompts
if we work from the command line, after entering into the system we will be faced with a shell that will allow us to interact with the system accepting our commands.
in the Linux world there are a variety of shell, we can distinguish between two main categories: shell compatible with Bourne shell and those compatible with the C shell .
these types of shell between them retain a certain degree of compatibility along with numerous differences mainly in terms of programming and controls for the settings of the same shell.
analyze only the bash shell (Bourne Again Shell ), the shell compatible with Bourne created by the GNU project which is one of the most popular and most powerful Linux offering on the line editing command and the presence of a command history and other data.
to know which shell you are using the command:
# echo $ SHELL
within the same shell distinguish between:
- login shell - you start when you log in the system;
- interactive shell - which allow you to enter commands, you may also login (think terminal launched by Environment graph);
- non-interactive shells - those launched whenever I execute a script.
depending on the type of shell the system will read various configuration files.
uses the bash shell, for its operation, some system files ( / etc / profile , / etc / bashrc , / etc / profile.d / ) plus a few files in your home that allow you to customize the shell environment for the individual user.
in particular depending on the type of shell reads the following files:
- login shell : / etc / profile and then from his home . Bash_profile , . Bash_login , . profile ( of these last three will be read only the first existing file )
- login shell : . bash_logout , this file is scanned at the shell
- interactive : . bashrc
- non-interactive : environment variable BASH_ENV
sure that in the file. Bash_profile (or . profile) there are the following lines:
if [-f ~ /. bashrc] then
source ~ /. bashrc fi
in this way every time you run the login shell will also read. bashrc (if any).
we then any modification. Bashrc with confidence that this will ever read.
if we want the changes affect all users system will act on the files in / etc / (profile, etc ...) but if we are concerned we will act on the individual user configuration files in his home, (. bashrc. bash_profile, etc. ...).
after modifying the configuration file to make the changes to the system we need to reread the changed file with the command source filename:
# source. Bashrc
environment variables
it may happen that after you install a program, type the command (eg firefox), which should start it and just get a terse "Command not found" or similar. the problem lies in the fact that the shell searches for programs in certain directories that are listed in the PATH environment variable.
if we want to start that program or enter the full path (eg / usr / local / bin firefox) or modify the environment variable.
this operation is very simple to type in a shell:
export PATH = $ PATH: / folder / da_aggiungere / al_path
(eg: export PATH = $ PATH: / usr / local / bin)
or if we make the changes permanent, write something like this:
PATH = $ PATH: / usr / local / bin
export PATH
in
. Bashrc if we change the variable for a single user or in / etc / profile (but this file may vary depending on the distribution) if we want the change affects all users system.
after editing the file. Bashrc you need to reread the file system in question with the following commands:
# source ~ /. bashrc (or. ~. / Bashrc)
NB Please note that the command shell will start from the first folder listed and continue to the right.
so in our example above, / usr / local / bin / folder will be the last attempt in which the shell.
management ALIAS
aliases are a convenient mechanism to allow you to assign names to more easily remembered commands that you entered in the shell normally.
for example, by typing the following lines in a shell:
alias ll = 'ls-ltr'
assign alias ll ls-ltr.
'll just type it will be to achieve the same output of ls-ltr.
Prompt
after being logged in (login) will appear prompt, as follows:
administrator @ matrix: ~ $
usually ends with the $ prompt if the user logged on is a normal user, and ends with # if the user is logged root.
this behavior, as well as the rest of the prompt may be changed by acting on several variables: PS1 and PS2, the first allows you to change the prompt while the second allows you to specify the symbol used when the command is completed over several lines.
Some examples:
# export PS1 = '\\ u @ \\ h>'
can get this: administrator @ matrix>
other variables can insertion in the prompt can be found with a "man bash", here are some:
\\ d - Date
\\ w - Current Directory
\\ u - Username
\\ t - Current
\\ s - name of the shell
make permanent the prompt
as Path alias and just put it in a configuration file with the following syntax:
PS1 = '\\ w @ \\ u>' export
PS1