Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revisionLast revisionBoth sides next revision | ||
linux:bash [2022/02/08 15:22] – mh | linux:bash [2022/02/28 14:53] – [Redirect to one file] mh | ||
---|---|---|---|
Line 3: | Line 3: | ||
===== Generalities ===== | ===== Generalities ===== | ||
- | Most of this comes from the excellent | + | Most of this comes from the greatest |
- | Bash is a **shell program** written to listen for **commands** from users and execute them. There are other shell programs (C shell, Z shell, Korn shell, etc.). | + | Bash is a **shell program** written to listen for **commands** from users and execute them. There are other shell programs (C shell, Z shell, Korn shell, etc.) so it is important to know for what shell you are writing code for. |
Bash uses **text-based interface** to interact with the users. It takes input (Std In) as text and displays output (Std Out) and error (Std Err) as text using a **terminal emulator** program. | Bash uses **text-based interface** to interact with the users. It takes input (Std In) as text and displays output (Std Out) and error (Std Err) as text using a **terminal emulator** program. | ||
Line 15: | Line 15: | ||
Bash has **synchronous command execution** meaning it will execute commands one at a time and users cannot interact with bash while it is executing a command. | Bash has **synchronous command execution** meaning it will execute commands one at a time and users cannot interact with bash while it is executing a command. | ||
- | Bash is **not a strict interpreter**. The discipline of writing clear, safe and precise code lies heavily upon the user. | ||
<WRAP round important> | <WRAP round important> | ||
- | **Don' | + | Bash is **not a strict interpreter**. |
+ | |||
+ | **Beware of the ambiguity** we are used to while expressing ourselves with human languages. | ||
+ | |||
+ | The **discipline of writing clear, safe and precise code** lies heavily upon the user. | ||
+ | |||
+ | __**Don' | ||
</ | </ | ||
Line 24: | Line 29: | ||
<WRAP round info> | <WRAP round info> | ||
- | Bash commands tell bash to perform a certain unit of work. These units of work cannot be subdivided: bash needs to know the whole command to be able to execute it. | + | Bash commands tell bash to perform a certain unit of work. These units of work cannot be subdivided: bash needs to know the whole command to be able to execute it. Also, bash reads commands line-by-line. |
There are different kinds of commands for different types of operations. Some commands group other commands into blocks or test their result. | There are different kinds of commands for different types of operations. Some commands group other commands into blocks or test their result. | ||
Line 30: | Line 35: | ||
Many command types are syntax sugar: their effect can be achieved differently, | Many command types are syntax sugar: their effect can be achieved differently, | ||
</ | </ | ||
+ | |||
+ | ==== Variables ==== | ||
+ | |||
+ | Before a command' | ||
==== Basic commands ==== | ==== Basic commands ==== | ||
Line 36: | Line 45: | ||
Bash performs a search using this name and looks for : | Bash performs a search using this name and looks for : | ||
- | *alias (first) | + | *alias (before anything else) |
*functions | *functions | ||
*built-in commands | *built-in commands | ||
Line 54: | Line 63: | ||
$ echo $name | $ echo $name | ||
john | john | ||
+ | </ | ||
+ | ---- | ||
+ | |||
+ | === type === | ||
+ | |||
+ | Displays information on a command, and where it is stored. | ||
+ | |||
+ | //Note that the **type** command and the **which** program are different and give different outputs// | ||
+ | |||
+ | **Example** | ||
+ | <code bash> | ||
+ | $ type ls | ||
+ | ls is aliased to 'ls -al' | ||
</ | </ | ||
---- | ---- | ||
Line 97: | Line 119: | ||
They can be a filename, a variable name, the name of a program or just a litteral. | They can be a filename, a variable name, the name of a program or just a litteral. | ||
+ | |||
+ | Multiple arguments can be used, separated by a blank space | ||
</ | </ | ||
Line 319: | Line 343: | ||
As a result, both file descriptors are connected to the same stream. | As a result, both file descriptors are connected to the same stream. | ||
+ | Be careful not to write something like '' | ||
</ | </ | ||
Line 350: | Line 375: | ||
To make a script out of a file containing bash commands, add a hashbang at the beginning of the file : | To make a script out of a file containing bash commands, add a hashbang at the beginning of the file : | ||
- | This is a direct path to bash in many GNU/Linux distributions | + | This is a direct path to bash in many GNU/Linux distributions |
<code bash> | <code bash> | ||
# | # | ||
</ | </ | ||
- | This invokes the ' | + | This rather more precise alternative |
<code bash> | <code bash> | ||
# | # |