Bourne-Again Shell
Bash , acronym of Bourne-again Shell , is the Shell project GNU. Its name is a word game on the name of the historical Shell of Unix, the Bourne Shell: Bourne again / born again means “again born” or “réincarné”. Based on this last, it makes many improvements, coming in particular from the Korn Shell and the C Shell. Bash is a Free software published under general public License (LPG). It is the interprets by defect on many free Unix, in particular on the systems GNU/Linux. It is also Shell owing to lack of Mac OS X and it was carried under Windows by the project Cygwin.
History
Its original author is Brian Fox of the Free Software Foundation, relayed later by Chet Ramey. The Bourne Shell original was written by Steve Bourne.
Interactive operation
Bash uses the library Readline what allows him, like C Shell, automatically to supplement the names of orders and files during a striking on the key, which accelerates work considerably. Keys UP and DOWN make it possible to sail with facility in the history of the orders.
Process control language
The first word of the line is thus regarded by the interpreter as a name of order. But there are several kinds, with various types of priority. In the decreasing order of priority:
- a alias: it is a word defined as synonym of another (group of) word (S). In this case, the interpreter starts by replacing the word by his equivalent.
- an order intern: it is an order which was defined in the interpreter himself, it is not the subject of a separate program. For example, the orders " cd" (change directory) or " set" are internal orders of Shell.
- an order externe, i.e. a program (or a command file, in general called script) stored on the disc of the machine. For example,
/bin/lsis the order which makes it possible to list the files contained in a given repertory.
Each order respects the following constraints:
- the premier word of the line is interpreted like the nom order, the other words are the parameters or options;
- each word is separated by one or more caractères from séparation. By defect, these characters are space and the tabulation (modifiable thanks to the Variable YEWS: Internal Field Separator);
- the end of the order is marked, that is to say by a " ; " (if one wants to place several orders on the same line), that is to say by a jump of line.
$ PATH
In the case of an external order, Shell must find the program before being able to carry out it. An exhaustive research, for each order, in all the filesystem would take far too much time and would make in practice the system unusable. Only a small whole of repertories is in fact consulted at the time of the research of the program allowing the execution of the order. These repertories are defined in a variable of environment called " $ PATH ". If the order is not found in one of the repertories listed in the PATH, the execution shows an error message of the " type; command not found".Contrary to what occurs under Windows, for safety reasons, Shell UNIX (and thus bash) do not include the current directory implicitly in the PATH, but it can be placed there explicitly.
Session
The closing of session will be done by the orderexit or a " Ctrl D" (the end mark of file under UNIX: the user closes the flow of reading of the interpreter).
Syntax
Each order is associated with- a standard entry (stdin)
- a standard exit (stdout)
- an exit of error (stderr)
Métacaractères of Shell
A métacaractère is a character which has a significance beyond its literal significance. Some examples on the level of the rational expressions in Bash:
- " *" : corresponds to any character, repeated 0,1 or several times.
- "? " : is equivalent to an unspecified character.
And others on the level of the Bash orders:
- " `" : interpret the character string included between two of these characters like an order. Example:
for file in `ls `; - " \ " : prevent the special interpretation of a métacaractère;
- " '" : all the characters included between two of these characters are interpreted like simple text.
Management of process
Management of flow
There exist three major flows:- the entry (or “ input ”) standard (entry 0);
- the exit (or “ output ”) standard (entry 1);
- the exit of standard error (entered 2)
Redirection of the entry and the 2 exits
-
one uses > to make the redirection of the standard exit (stdout) of an order
- 2> for the redirection of the exit “of the errors” (stderr)
generally n> allows the redirection of the nième descriptor of file
-
&> to redirect at the same time the standard exit and the exit error:
Variables of Shell
The variables are referred by making them precede by the sign $: example echo $HOMESome variable of environment: TO USE PID HOME PATH SHELL
Substitution of orders
in a line of order, one replaces like argument an order by his result (with the stdout) by surrounding it of reversed apostrophes `name orders `or by using $ () $ (name orders)
rational Expression
To supplement
Escape character backslash (" \ ")
Backslash at the end of the line
At the end of a line, a backslash indicates that the order continues with the following line. This function is particularly useful for the great orders in order to make them more easily readable.
Backslash to form one of the special characters of the C
The chains having a format similar to $' \ n' are interpreted in a particular way by the bash. They are transformed into conformity with the rules of the C ANSI. Example: echo $ ' \ a' # Will cause a sound beep.Here the list:
See ASCII
Backslash before one of the meta-characters of the bash
Meta-characters, in particular " *" (star), are interpreted by the interpreter bash (generally replacement by possible files), which is awkward in certain cases (order find , sed,… etc); example: Cd /etc; find. - name r* The error message will be Find: The ways must precede the expressionOne of the solutions is to use a backslash before the character " *". Example: Cd /etc; find. - name R \ *
Notice
- Another solution would be to use the quotation marks.
Possible scripts of starting and disconnection
Script carried out at the time of connection- Common to all the users
- /etc/profile
- Specific to each user
- .bash_profile
- .bash_login
- .profile
Scripts of disconnection
- .bash_logout
Script for Shell interactives other than scripts of connection:
- .bashrc
References
| Random links: | Analyzes plant health risk | Jean-Luc Moudenc | Palleau | 1.FC Kosice | Furnace bridge of the peace of Auguste | David_Dimbleby |