Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| elearning:workbooks:redhat:rh124en:l104 [2024/11/11 13:10] – admin | elearning:workbooks:redhat:rh124en:l104 [2024/11/26 10:56] (Version actuelle) – admin | ||
|---|---|---|---|
| Ligne 5: | Ligne 5: | ||
| Last update : ~~LASTMOD~~ | Last update : ~~LASTMOD~~ | ||
| - | ====== RH12405 - The Command Line====== | + | ====== RH12405 - The Command Line Interface====== |
| =====Contents===== | =====Contents===== | ||
| - | * **RH12405 - The Command Line** | + | * **RH12405 - The Command Line Interface** |
| * Contents | * Contents | ||
| * The Shell | * The Shell | ||
| Ligne 29: | Ligne 29: | ||
| * @(expression) | * @(expression) | ||
| * !(expression) | * !(expression) | ||
| - | * Escape characters | + | * Protecting Metacharacters |
| - | * 1.9 - Return | + | * 1.9 - Exit Codes |
| * 1.10 - Redirections | * 1.10 - Redirections | ||
| * 1.11 - Pipes | * 1.11 - Pipes | ||
| Ligne 37: | Ligne 37: | ||
| * 1.14 - Displaying shell variables | * 1.14 - Displaying shell variables | ||
| * Main variables | * Main variables | ||
| - | * Regionalisation | + | * Internationalization |
| * Special variables | * Special variables | ||
| * 1.15 - The env command | * 1.15 - The env command | ||
| Ligne 46: | Ligne 46: | ||
| * nounset | * nounset | ||
| - | =====Le Shell===== | + | =====The Shell===== |
| A shell is a **command line interpreter** (C.L.I). It is used as an interface to give instructions or **commands** to the operating system. | A shell is a **command line interpreter** (C.L.I). It is used as an interface to give instructions or **commands** to the operating system. | ||
| Ligne 72: | Ligne 72: | ||
| This module is about using the **bash** shell under Linux. The **bash** shell allows you to: | This module is about using the **bash** shell under Linux. The **bash** shell allows you to: | ||
| - | * Recall commands | + | * Recall |
| - | * Generate | + | * Auto-generate |
| - | * Use aliases | + | * Use Aliases |
| - | * Use array variables | + | * Use tables |
| - | * Use numeric variables and C language | + | * Use C language |
| - | * Managing character | + | * Manage |
| - | * Using functions | + | * Use Functions |
| A command always begins with a keyword. This keyword is interpreted by the shell according to the type of command and in the following order: | A command always begins with a keyword. This keyword is interpreted by the shell according to the type of command and in the following order: | ||
| - | | + | |
| - | | + | |
| - | - Internal shell commands | + | |
| - | | + | |
| - | ====1.1 - Internal | + | ====1.1 - Built-in |
| - | Internal | + | Built-in |
| < | < | ||
| Ligne 376: | Ligne 376: | ||
| [trainee@redhat9 ~]$ ls | [trainee@redhat9 ~]$ ls | ||
| aac abc bca Desktop Documents Downloads Music Pictures Public Templates Videos vitext xyz | aac abc bca Desktop Documents Downloads Music Pictures Public Templates Videos vitext xyz | ||
| + | |||
| [trainee@redhat9 ~]$ !! | [trainee@redhat9 ~]$ !! | ||
| ls | ls | ||
| Ligne 403: | Ligne 404: | ||
| 90 ls | 90 ls | ||
| 91 history | 91 history | ||
| + | |||
| [trainee@redhat9 ~]$ !90 | [trainee@redhat9 ~]$ !90 | ||
| ls | ls | ||
| Ligne 461: | Ligne 463: | ||
| < | < | ||
| [trainee@redhat9 ~]$ mo | [trainee@redhat9 ~]$ mo | ||
| - | modinfo modulemd-validator more mount.composefs mount.fuse3 | + | modinfo |
| - | modprobe monitor-sensor mount mount.fuse mountpoint | + | modprobe |
| </ | </ | ||
| ====1.7 - The interactive shell ==== | ====1.7 - The interactive shell ==== | ||
| - | When using the shell, we often need to execute a command on several files instead of processing them individually. For this purpose we can use special characters. | + | When using the shell, we often need to execute a command on several files instead of processing them individually. For this purpose we can use metacharacters. |
| ^ Metacharacter ^ Description ^ | ^ Metacharacter ^ Description ^ | ||
| Ligne 494: | Ligne 496: | ||
| </ | </ | ||
| - | To demonstrate the use of the special character | + | To demonstrate the use of the metacharacter |
| < | < | ||
| Ligne 530: | Ligne 532: | ||
| ^ Metacharacter ^ Description ^ | ^ Metacharacter ^ Description ^ | ||
| | [xyz] | Represents either x or y or z | | | [xyz] | Represents either x or y or z | | ||
| - | | [m-t] | Represents a character in the range m to t | + | | [m-t] | Represents a character in the range m to t | |
| | [!xyz] | Represents any character other than x or y or z | | | [!xyz] | Represents any character other than x or y or z | | ||
| | [!m-t] | Represents any character outside of the range m to t | | | [!m-t] | Represents any character outside of the range m to t | | ||
| Ligne 589: | Ligne 591: | ||
| ====1.8 - The extglob option==== | ====1.8 - The extglob option==== | ||
| - | Enable the **extglob** option in the bash shell so that you can use **? | + | Enable the **extglob** option in the bash shell so that you can use **? |
| < | < | ||
| Ligne 726: | Ligne 728: | ||
| </ | </ | ||
| - | ===Escaping characters=== | + | ====Protecting Metacharacters==== |
| - | In order to use a special character | + | In order to use a metacharacter |
| ^ Character ^ Description ^ | ^ Character ^ Description ^ | ||
| - | | Protects | + | | \ | Escapes |
| - | | Protects any character, except the **‘** character itself, | + | | ' ' |
| - | | Protects any character, with the exception of the **‘** character itself, | + | | " " |
| To illustrate the use of escape characters, consider the following command: | To illustrate the use of escape characters, consider the following command: | ||
| - | echo * is a special character | + | echo * is a metacharacter |
| When you enter this command in your **training** directory, you will get a window similar to this one: | When you enter this command in your **training** directory, you will get a window similar to this one: | ||
| < | < | ||
| - | [trainee@redhat9 training]$ echo * is a special character | + | [trainee@redhat9 training]$ echo * is a metacharacter |
| - | a100 f f1 f123123123.txt f123123.txt f123123.txt f2 f3 f4 f5 f52 f62 f.txt is a special character | + | a100 f f1 f123123123.txt f123123.txt f123123.txt f2 f3 f4 f5 f52 f62 f.txt is a metacharacter |
| - | [trainee@redhat9 training]$ echo \* is a special character | + | [trainee@redhat9 training]$ echo \* is a metacharacter |
| - | * is a special character | + | * is a metacharacter |
| - | [trainee@redhat9 training]$ echo ‘* is a special character | + | [trainee@redhat9 training]$ echo "* is a metacharacter" |
| - | * is a special character | + | * is a metacharacter |
| - | [trainee@redhat9 training]$ echo ‘* is a special character’ * is a special character | + | [trainee@redhat9 training]$ echo ‘* is a metacharacter’ |
| - | * is a special character | + | * is a metacharacter |
| </ | </ | ||
| ====1.9 - Exit codes==== | ====1.9 - Exit codes==== | ||
| - | Each command returns | + | Each command returns |
| For example: | For example: | ||
| Ligne 773: | Ligne 775: | ||
| </ | </ | ||
| - | In this example the **codes** directory was created successfully. The return | + | In this example the **codes** directory was created successfully. The exit code stored in the $? variable is a zero. |
| - | Deleting the directory encountered an error because **codes** contained the file **return**. The return | + | Deleting the directory encountered an error because **codes** contained the file **return**. The exit code stored in the $? variable is **one**. |
| - | If the return | + | If the exit code is **zero**, the last command was executed without error. |
| - | If the return | + | If the exit code is **other than zero**, the last command was completed with an error. |
| ====1.10 - Redirections==== | ====1.10 - Redirections==== | ||
| Ligne 801: | Ligne 803: | ||
| [trainee@redhat9 training]$ free > file | [trainee@redhat9 training]$ free > file | ||
| [trainee@redhat9 training]$ cat file | [trainee@redhat9 training]$ cat file | ||
| - | total used free shared buff/cache available | + | |
| - | Mem: 7869560 996400 4964048 15324 2229600 6873160 | + | Mem: |
| - | Swap: 5242876 0 5242876 | + | Swap: 5242876 |
| </ | </ | ||
| Ligne 819: | Ligne 821: | ||
| < | < | ||
| + | [trainee@redhat9 training]$ free >> file | ||
| [trainee@redhat9 training]$ free >> file | [trainee@redhat9 training]$ free >> file | ||
| [trainee@redhat9 training]$ cat file | [trainee@redhat9 training]$ cat file | ||
| Thu Sep 26 12:49:11 PM CEST 2024 | Thu Sep 26 12:49:11 PM CEST 2024 | ||
| - | total used free shared buff/cache available | + | |
| - | Mem: 7869560 996392 4964048 15324 2229608 6873168 | + | Mem: |
| - | Swap: 5242876 0 5242876 | + | Swap: 5242876 |
| </ | </ | ||
| Ligne 850: | Ligne 853: | ||
| In fact the error is generated because the **training** directory is not empty. | In fact the error is generated because the **training** directory is not empty. | ||
| - | We can also gather channels. To apply this, we need to understand that the shell processes commands from **left to right**. | + | You can join file descriptors using the **&** character: |
| - | + | ||
| - | In the following example, we join the output channel and the error channel: | + | |
| < | < | ||
| Ligne 927: | Ligne 928: | ||
| Thu Sep 26 12:56:02 PM CEST 2024 | Thu Sep 26 12:56:02 PM CEST 2024 | ||
| - | [trainee@redhat9 ~]$ echo `date | + | [trainee@redhat9 ~]$ echo `date` |
| Thu Sep 26 12:56:17 PM CEST 2024 | Thu Sep 26 12:56:17 PM CEST 2024 | ||
| </ | </ | ||
| Ligne 943: | Ligne 944: | ||
| This example sends the results of the three commands to the **list** file, processing them in the background. | This example sends the results of the three commands to the **list** file, processing them in the background. | ||
| - | The commands can also be chained according to the return | + | The commands can also be chained according to the exit code of the previous command. |
| **&& | **&& | ||
| Ligne 1001: | Ligne 1002: | ||
| | TMOUT | The number of seconds less 60 before an unused terminal gets sent the **exit** command. | | | TMOUT | The number of seconds less 60 before an unused terminal gets sent the **exit** command. | | ||
| - | === Regionalisation | + | === Internationalization |
| - | Internationalisation**, also known as **i18n** because there are 18 letters between the letter **I** and the letter **n** in the word // | + | **Internationalization**, also known as **i18n** because there are 18 letters between the letter **I** and the letter **n** in the word // |
| - | * word length | + | * Text processing differences, |
| - | * accents | + | * Writing direction, |
| - | * writing from left to right or right to left, | + | * Different systems of numerals, |
| - | * currency units | + | * Telephone numbers, addresses |
| - | * typographic styles | + | * Weights and measures, |
| - | * units of measurement, | + | * Date/time format, |
| - | * date and time display, | + | * Paper sizes, |
| - | * print formats, | + | * Keyboard layout, |
| - | * keyboard format, | + | * etc ... |
| - | * keyboard format, | + | |
| - | The **Regionalisation**, also called **l10n** because there are 10 letters between the letter **L** and the letter n in the word //Localisation//, consists of modifying the internalisation according to a specific region. | + | The **Localization**, also called **l10n** because there are 10 letters between the letter **L** and the letter n in the word //Localization//, consists of modifying the internalisation according to a specific region. |
| The complete country code takes the following form: **language-PAYS.character_set**. For example, for the English language the language-PAYS values are : | The complete country code takes the following form: **language-PAYS.character_set**. For example, for the English language the language-PAYS values are : | ||
| Ligne 1088: | Ligne 1088: | ||
| HOME=/ | HOME=/ | ||
| LANG=en_US.UTF-8 | LANG=en_US.UTF-8 | ||
| - | LS_COLORS=rs=0: | ||