Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| elearning:workbooks:redhat:rh124en:l104 [2024/11/23 15:47] – admin | elearning:workbooks:redhat:rh124en:l104 [2024/11/26 10:56] (Version actuelle) – admin | ||
|---|---|---|---|
| Ligne 29: | Ligne 29: | ||
| * @(expression) | * @(expression) | ||
| * !(expression) | * !(expression) | ||
| - | * Escape characters | + | * Protecting Metacharacters |
| * 1.9 - Exit Codes | * 1.9 - Exit Codes | ||
| * 1.10 - Redirections | * 1.10 - Redirections | ||
| 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: | ||
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| ====1.1 - Built-in and External Shell Commands==== | ====1.1 - Built-in and External Shell Commands==== | ||
| 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 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 1005: | Ligne 1006: | ||
| **Internationalization**, | **Internationalization**, | ||
| - | * 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 **Localization**, | The **Localization**, | ||
| Ligne 1088: | Ligne 1088: | ||
| HOME=/ | HOME=/ | ||
| LANG=en_US.UTF-8 | LANG=en_US.UTF-8 | ||
| - | LS_COLORS=rs=0: | ||