Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
elearning:workbooks:redhat:rh124en:l104 [2024/11/11 13:08] adminelearning: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
     * LAB #1 - The /bin/bash Shell     * LAB #1 - The /bin/bash Shell
-      * 1.1 - Internal and External Commands+      * 1.1 - Shell Internal and External Commands
       * 1.2 - Aliases       * 1.2 - Aliases
       * 1.3 - Defining a user's shell       * 1.3 - Defining a user's shell
Ligne 20: Ligne 20:
       * 1.6 - Generating file name endings       * 1.6 - Generating file name endings
       * 1.7 - The interactive shell       * 1.7 - The interactive shell
-        * The Metacharacter +        * Character 
-        * The Metacharacter +        * Character 
-        * The [] Metacharacter+        * Character [ ]
       * 1.8 - The extglob option       * 1.8 - The extglob option
         * ?(expression)         * ?(expression)
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
     * 1.11 - Pipes     * 1.11 - Pipes
-    * 1.12 - Command substitutions+    * 1.12 - Command substitution
     * 1.13 - Command chaining     * 1.13 - Command chaining
     * 1.14 - Displaying shell variables     * 1.14 - Displaying shell variables
       * Main variables       * Main variables
-      * Regionalisation and internationalisation variables+      * Internationalization and Localization Variables
       * 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. 
  
 The word shell is generic. There are many shells in the Unix world, for example : The word shell is generic. There are many shells in the Unix world, for example :
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 previously typed commands 
-  * Generate the end of file names +  * Auto-generate the end of file name 
-  * Use aliases +  * Use Aliases 
-  * Use array variables +  * Use tables 
-  * Use numeric variables and C language arithmetic +  * Use C language numerical and math variables 
-  * Managing character strings +  * Manage strings 
-  * 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:
  
-  - Aliases +  * An Alias, 
-  - Functions +  * A Function, 
-  - Internal shell commands +  * A Built-in Command, 
-  External commands+  * An External Command.
  
-====1.1 - Internal and External Shell Commands====+====1.1 - Built-in and External Shell Commands====
  
-Internal shell commands are commands such as **cd**. To check the type of command, use the **type** command:+Built-in shell commands are commands such as **cd**. To check the type of command, use the **type** command:
  
 <code> <code>
Ligne 296: Ligne 296:
  
   * **$** for a normal user,   * **$** for a normal user,
-  **#** for root.+  **#** for root.
  
 ====1.5 - Recalling commands ==== ====1.5 - Recalling 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:
 <code> <code>
 [trainee@redhat9 ~]$ mo [trainee@redhat9 ~]$ mo
-modinfo modulemd-validator more mount.composefs mount.fuse3          +modinfo             modulemd-validator  more                mount.composefs     mount.fuse3          
-modprobe monitor-sensor mount mount.fuse mountpoint +modprobe            monitor-sensor      mount               mount.fuse          mountpoint 
 </code> </code>
  
 ====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:
 </code> </code>
  
-To demonstrate the use of the special character *, enter the following command:+To demonstrate the use of the metacharacter *, enter the following command:
  
 <code> <code>
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 **?(expression), *(expression), +(expression), @(expression) and !(expression)** :+Enable the **extglob** option in the bash shell so that you can use **?(expression), *(expression), +(expression), @(expression) and !(expression)**:
  
 <code> <code>
Ligne 726: Ligne 728:
 </WRAP> </WRAP>
  
-===Escaping characters===+====Protecting Metacharacters====
  
-In order to use a special character in a literal context, an escape character must be used. There are three escape characters:+In order to use a metacharacter in a literal context, an escape character must be used. There are three escape characters:
  
 ^ Character ^ Description ^ ^ Character ^ Description ^
-Protects the character that follows it +\ | Escapes the character which immediately follows | 
-| Protects any character, except the **‘** character itself, between the two ****. +| ' ' | Protects any character between the two **'** | 
-| Protects any character, with the exception of the **** character itself, **$**, **\** and **’**, between the two **"** |.+| " " | Protects any character between the two **"** except the following: **$**, **\** and **'** |
  
 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 [Enter].+  echo * is a metacharacter [Enter].
  
 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:
  
 <code> <code>
-[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
 </code> </code>
  
 ====1.9 - Exit codes==== ====1.9 - Exit codes====
  
-Each command returns a code at the end of its executionThe special variable **$?** is used to store the return code of the last command executed.+Each command returns an **exit status** when it is executedThis exit status is stored in a special variable**$?**.
  
 For example: For example:
Ligne 773: Ligne 775:
 </code> </code>
  
-In this example the **codes** directory was created successfully. The return code stored in the $? variable is a zero.+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 code stored in the $? variable is **one**.+Deleting the directory encountered an error because **codes** contained the file **return**. The exit code stored in the $? variable is **one**.
  
-If the return code is **zero**, the last command was executed without error. +If the exit code is **zero**, the last command was executed without error. 
  
-If the return code is **other than zero**, the last command was completed with an error. +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 +               total        used        free      shared  buff/cache   available 
-Mem: 7869560 996400 4964048 15324 2229600 6873160 +Mem:         7869560      996400     4964048       15324     2229600     6873160 
-Swap: 5242876 0 5242876+Swap:        5242876               5242876
 </code> </code>
  
Ligne 819: Ligne 821:
  
 <code> <code>
 +[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 +               total        used        free      shared  buff/cache   available 
-Mem: 7869560 996392 4964048 15324 2229608 6873168 +Mem:         7869560      996392     4964048       15324     2229608     6873168 
-Swap: 5242876 0 5242876+Swap:        5242876               5242876
 </code> </code>
  
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:+
  
 <code> <code>
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
 </code> </code>
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 code of the previous command.+The commands can also be chained according to the exit code of the previous command.
  
 **&&** is used to ensure that the second command is executed if the output status value is 0, i.e. there were no errors.  **&&** is used to ensure that the second command is executed if the output status value is 0, i.e. there were no errors. 
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 and Internationalisation Variables ===+=== Internationalization and Localization Variables ===
  
-Internationalisation**, also known as **i18n** because there are 18 letters between the letter **I** and the letter **n** in the word //Internationalization//, involves adapting software to parameters that vary from one region to another: +**Internationalization**, also known as **i18n** because there are 18 letters between the letter **I** and the letter **n** in the word //Internationalization//, involves adapting software to parameters that vary from one region to another: 
  
-  * 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 and international postal codes,  
-  * typographic styles and editorial models,  +  * Weights and measures,  
-  * units of measurement,  +  * Date/time format
-  * date and time display,  +  * Paper sizes,  
-  * print formats,  +  * Keyboard layout
-  * keyboard format+  * etc ...
-  * keyboard format, etc.+
  
-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/trainee HOME=/home/trainee
 LANG=en_US.UTF-8 LANG=en_US.UTF-8
-LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*. tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*. lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*. sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*. mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*. pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*. asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*. aac=01;36:*.au=01;36:*.flac=01;36:*.m4a=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.oga=01;36:*.opus=01;36:*.spx=01;36:*.xspf=01;36:+LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.m4a=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.oga=01;36:*.opus=01;36:*.spx=01;36:*.xspf=01;36:
 SSH_CONNECTION=10.0.2.1 37578 10.0.2.101 22 SSH_CONNECTION=10.0.2.1 37578 10.0.2.101 22
 XDG_SESSION_CLASS=user XDG_SESSION_CLASS=user
Ligne 1107: Ligne 1107:
 MAIL=/var/spool/mail/trainee MAIL=/var/spool/mail/trainee
 SSH_TTY=/dev/pts/0 SSH_TTY=/dev/pts/0
-BASH_FUNC_which%%=() { ( alias;+BASH_FUNC_which%%=() {  ( alias;
  eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@  eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@
 } }
Ligne 1229: Ligne 1229:
 </code> </code>
  
-Among the options, here is a description of the most interesting ones:+These are the most interesting options:
  
 ^ Option ^ Default value ^ Description ^ ^ Option ^ Default value ^ Description ^
Ligne 1235: Ligne 1235:
 | emacs | on | emacs editing mode | | emacs | on | emacs editing mode |
 | noclobber  | off | Simple re-directions do not squash the target file if it exists | | noclobber  | off | Simple re-directions do not squash the target file if it exists |
-| noglob | off | Turns off special characters |+| noglob | off | Turns off metacharacters |
 | nounset | off | The shell will return an error if the variable is not set | | nounset | off | The shell will return an error if the variable is not set |
 | verbose | off | Echos back the typed command | | verbose | off | Echos back the typed command |
Ligne 1270: Ligne 1270:
  
 <WRAP center round important 60%> <WRAP center round important 60%>
-**Important**: Note that the effect of the special character is cancelled under the influence of the **noglob** option.+**Important**: Note that the effect of the metacharacter is cancelled under the influence of the **noglob** option.
 </WRAP> </WRAP>
  
Ligne 1286: Ligne 1286:
  
 <WRAP center round important 60%> <WRAP center round important 60%>
-**Important**: Note that the non-existent variable **$FENESTROS** is identified as such under the influence of the **nounset** option. Now the usual behaviour of Linux is to return an empty line which does not indicate whether the variable does not exist or whether it is simply empty.+**Important**: Note that the non-existent variable **$FENESTROS** is identified as such under the influence of the **nounset** option. Now the usual behavior of Linux is to return an empty line which does not indicate whether the variable does not exist or whether it is simply empty.
 </WRAP> </WRAP>
  
 ----- -----
 Copyright © 2024 Hugh Norris. Copyright © 2024 Hugh Norris.
Menu