Différences

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

Lien vers cette vue comparative

Prochaine révision
Révision précédente
elearning:workbooks:rhel:6:utilisateur:l105 [2020/01/30 03:28] – external edit 127.0.0.1elearning:workbooks:rhel:6:utilisateur:l105 [2023/07/27 13:56] (Version actuelle) admin
Ligne 1: Ligne 1:
 ~~PDF:LANDSCAPE~~ ~~PDF:LANDSCAPE~~
  
-Dernière mise-à-jour ~~LASTMOD~~+Version **2023.01**
  
-======Command Line Interface======+Updated : ~~LASTMOD~~ 
 + 
 +====== LCE405 - Command Line Interface====== 
 + 
 +=====Contents===== 
 + 
 +  * **LCE405 - Command Line Interface** 
 +    * Contents 
 +    * The Shell 
 +    * /bin/bash 
 +      * Internal And External Commands 
 +      * Aliases 
 +      * The Prompt 
 +      * The history Command 
 +      * The TAB key 
 +      * Metacharacters 
 +      * Protecting Metacharacters 
 +      * Exit Status 
 +      * Redirections 
 +      * Pipes 
 +      * Command Substitution 
 +      * Conditional Command Execution 
 +    * Environment Variables 
 +      * Principal Variables 
 +      * Internationalisation and Localisation 
 +      * Special Variables 
 +      * The env Command 
 +    * Bash Shell Options 
 +      * noclobber 
 +      * noglob 
 +      * nounset 
 +    * Basic Shell Scripting 
 +      * Execution 
 +      * The read command 
 +      * The test Command 
 +      * The %%[[ expression ]]%% Command 
 +      * Shell Operators 
 +      * The expr Command 
 +      * The let Command 
 +      * Control Structures 
 +      * Loops 
 +      * Start-up Scripts 
 +      * LAB #1 - Start-up Scripts
  
 =====The Shell===== =====The Shell=====
Ligne 20: Ligne 62:
 | zsh | Z Shell | 1990 | Paul Falstad | zsh | Zsh is an extended Bourne shell with a large number of improvements, including some features of bash, ksh, and tcsh: /usr/bin/zsh | | zsh | Z Shell | 1990 | Paul Falstad | zsh | Zsh is an extended Bourne shell with a large number of improvements, including some features of bash, ksh, and tcsh: /usr/bin/zsh |
  
-In RHEL/CentOS **/bin/sh** is a soft link to **/bin/bash** :+In RHEL/CentOS **/bin/sh** is a soft link to **/bin/bash** :
  
 <code> <code>
-[trainee@centos7 ~]$ ls -l /bin/sh +[trainee@centos8 ~]$ ls -l /bin/sh 
-lrwxrwxrwx. 1 root root 4 30 sept. 06:01 /bin/sh -> bash+lrwxrwxrwx. 1 root root 4 Jul 21  2020 /bin/sh -> bash
 </code> </code>
  
Ligne 49: Ligne 91:
  
 The /bin/bash shell comes with a set of built-in or //internal// commands. External commands are executable binaries or scripts generally found in one of the following directories: The /bin/bash shell comes with a set of built-in or //internal// commands. External commands are executable binaries or scripts generally found in one of the following directories:
- 
-      * /bin, 
-      * /sbin, 
-      * /usr/bin, 
-      * /usr/sbin. 
- 
-To check if a command is internal to the shell or external, use the **type** command: 
  
 <code> <code>
Ligne 62: Ligne 97:
 </code> </code>
  
-External commands are either binaries or scripts that can be found in /bin, /sbin, /usr/bin or /usr/sbin :+External commands are either binaries or scripts that can be found in /usr/bin or /usr/sbin:
  
 <code> <code>
-[trainee@centos7 ~]$ type passwd +[trainee@centos8 ~]$ type cd 
-passwd is /usr/bin/passwd+cd is a shell builtin
 </code> </code>
  
Ligne 74: Ligne 109:
  
 <code> <code>
-[trainee@centos7 ~]$ type ls+[trainee@centos8 ~]$ type ls
 ls is aliased to `ls --color=auto' ls is aliased to `ls --color=auto'
 </code> </code>
Ligne 85: Ligne 120:
  
 <code> <code>
-[trainee@centos7 ~]$ alias dir='ls -l' +[trainee@centos8 ~]$ alias dir='ls -l' 
-[trainee@centos7 ~]$ dir +[trainee@centos8 ~]$ dir 
-total 4 +total 0 
--rw-rw-r--. 1 trainee trainee   29 sept. 18:20 aac +-rw-rw-r--. 1 trainee trainee 0 Apr 20 03:46 aac 
--rw-rw-r--. 1 trainee trainee   29 sept. 18:20 abc +-rw-rw-r--. 1 trainee trainee 0 Apr 20 03:46 abc 
--rw-rw-r--. 1 trainee trainee   29 sept. 18:20 bca +-rw-rw-r--. 1 trainee trainee 0 Apr 20 03:46 bca 
-drwxr-xr-x. 2 trainee trainee   6 30 avril 11:54 Desktop +-rw-rw-r--. 1 trainee trainee 0 Apr 20 03:46 xyz
-drwxr-xr-x. 2 trainee trainee   6 30 avril 11:54 Documents +
-drwxr-xr-x. 2 trainee trainee   6 30 avril 11:54 Downloads +
-drwxr-xr-x. 2 trainee trainee   6 30 avril 11:54 Music +
-drwxr-xr-x. 2 trainee trainee   6 30 avril 11:54 Pictures +
-drwxr-xr-x. 2 trainee trainee   6 30 avril 11:54 Public +
-drwxr-xr-x. 2 trainee trainee   6 30 avril 11:54 Templates +
-drwxr-xr-x. 2 trainee trainee   6 30 avril 11:54 Videos +
--rw-rw-r--. 1 trainee trainee 442 29 sept. 00:53 vitext +
--rw-rw-r--. 1 trainee trainee   29 sept. 18:20 xyz+
 </code> </code>
  
Ligne 110: Ligne 136:
  
 <code> <code>
-[trainee@centos7 ~]$ alias+[trainee@centos8 ~]$ alias
 alias dir='ls -l' alias dir='ls -l'
 alias egrep='egrep --color=auto' alias egrep='egrep --color=auto'
Ligne 119: Ligne 145:
 alias ls='ls --color=auto' alias ls='ls --color=auto'
 alias vi='vim' alias vi='vim'
-alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'+alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot' 
 +alias xzegrep='xzegrep --color=auto' 
 +alias xzfgrep='xzfgrep --color=auto' 
 +alias xzgrep='xzgrep --color=auto' 
 +alias zegrep='zegrep --color=auto' 
 +alias zfgrep='zfgrep --color=auto' 
 +alias zgrep='zgrep --color=auto'
 </code> </code>
  
Ligne 129: Ligne 161:
  
 <code> <code>
-[trainee@centos7 ~]$ \dir +[trainee@centos8 ~]$ \dir 
-aac  bca      Documents  Music    Public     Videos  xyz +aac  abc  bca  xyz
-abc  Desktop  Downloads  Pictures  Templates  vitext+
 </code> </code>
  
Ligne 137: Ligne 168:
  
 <code> <code>
-[trainee@centos7 ~]$ unalias dir +[trainee@centos8 ~]$ unalias dir 
-[trainee@centos7 ~]$ dir +[trainee@centos8 ~]$ dir 
-aac  bca      Documents  Music    Public     Videos  xyz +aac  abc  bca  xyz
-abc  Desktop  Downloads  Pictures  Templates  vitext+
 </code> </code>
  
Ligne 146: Ligne 176:
  
 <code> <code>
-[trainee@centos7 ~]$ cat /etc/passwd+[trainee@centos8 ~]$ cat /etc/passwd
 root:x:0:0:root:/root:/bin/bash root:x:0:0:root:/root:/bin/bash
 bin:x:1:1:bin:/bin:/sbin/nologin bin:x:1:1:bin:/bin:/sbin/nologin
Ligne 159: Ligne 189:
 games:x:12:100:games:/usr/games:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin
 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
-nobody:x:99:99:Nobody:/:/sbin/nologin +nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin
-avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin +
-systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin +
-systemd-network:x:998:996:systemd Network Management:/:/sbin/nologin+
 dbus:x:81:81:System message bus:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin
-polkitd:x:997:995:User for polkitd:/:/sbin/nologin +systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin 
-abrt:x:173:173::/etc/abrt:/sbin/nologin +systemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin
-usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin +
-colord:x:996:993:User for colord:/var/lib/colord:/sbin/nologin +
-libstoragemgmt:x:995:992:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin +
-setroubleshoot:x:994:991::/var/lib/setroubleshoot:/sbin/nologin +
-rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin +
-rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin +
-chrony:x:993:990::/var/lib/chrony:/sbin/nologin +
-unbound:x:992:989:Unbound DNS resolver:/etc/unbound:/sbin/nologin+
 tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
-geoclue:x:991:988:User for geoclue:/var/lib/geoclue:/sbin/nologin +polkitd:x:998:996:User for polkitd:/:/sbin/nologin 
-ntp:x:38:38::/etc/ntp:/sbin/nologin +unbound:x:997:994:Unbound DNS resolver:/etc/unbound:/sbin/nologin 
-sssd:x:990:987:User for sssd:/:/sbin/nologin +libstoragemgmt:x:996:993:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin 
-rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin +cockpit-ws:x:995:991:User for cockpit-ws:/nonexisting:/sbin/nologin 
-nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin +sssd:x:994:990:User for sssd:/:/sbin/nologin 
-pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin +setroubleshoot:x:993:989::/var/lib/setroubleshoot:/sbin/nologin
-gdm:x:42:42::/var/lib/gdm:/sbin/nologin +
-gnome-initial-setup:x:989:984::/run/gnome-initial-setup/:/sbin/nologin +
-avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin +
-postfix:x:89:89::/var/spool/postfix:/sbin/nologin+
 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
 +chrony:x:992:988::/var/lib/chrony:/sbin/nologin
 tcpdump:x:72:72::/:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin
 trainee:x:1000:1000:trainee:/home/trainee:/bin/bash trainee:x:1000:1000:trainee:/home/trainee:/bin/bash
-vboxadd:x:988:1::/var/run/vboxadd:/bin/false +cockpit-wsinstance:x:991:987:User for cockpit-ws instances:/nonexisting:/sbin/nologin 
-named:x:25:25:Named:/var/named:/sbin/nologin+rngd:x:990:986:Random Number Generator Daemon:/var/lib/rngd:/sbin/nologin 
 +gluster:x:989:985:GlusterFS daemons:/run/gluster:/sbin/nologin 
 +qemu:x:107:107:qemu user:/:/sbin/nologin 
 +rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin 
 +rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin 
 +saslauth:x:988:76:Saslauthd user:/run/saslauthd:/sbin/nologin 
 +radvd:x:75:75:radvd user:/:/sbin/nologin 
 +dnsmasq:x:983:983:Dnsmasq DHCP and DNS server:/var/lib/dnsmasq:/sbin/nologin
 </code> </code>
  
Ligne 195: Ligne 218:
  
 <code> <code>
-[trainee@centos7 ~]$ cat /etc/shells+[trainee@centos8 ~]$ cat /etc/shells
 /bin/sh /bin/sh
 /bin/bash /bin/bash
-/sbin/nologin 
 /usr/bin/sh /usr/bin/sh
 /usr/bin/bash /usr/bin/bash
-/usr/sbin/nologin 
-/bin/tcsh 
-/bin/csh 
 </code> </code>
  
Ligne 209: Ligne 228:
  
 <code> <code>
-[trainee@centos7 ~]$ echo $SHELL+[trainee@centos8 ~]$ echo $SHELL
 /bin/bash /bin/bash
 </code> </code>
Ligne 220: Ligne 239:
  
 <code> <code>
-[trainee@centos7 ~]$ chsh+[trainee@centos8 ~]$ chsh
 Changing shell for trainee. Changing shell for trainee.
-New shell [/bin/bash]/bin/sh+New shell [/bin/bash] 
 +/bin/sh
 Password: trainee Password: trainee
 Shell changed. Shell changed.
Ligne 234: Ligne 254:
  
 <code> <code>
-[trainee@centos7 ~]$ echo $SHELL+[trainee@centos8 ~]$ echo $SHELL
 /bin/bash /bin/bash
 </code> </code>
Ligne 241: Ligne 261:
  
 <code> <code>
-[trainee@centos7 ~]$ cat /etc/passwd | grep trainee+[trainee@centos8 ~]$ cat /etc/passwd | grep trainee
 trainee:x:1000:1000:trainee:/home/trainee:/bin/sh trainee:x:1000:1000:trainee:/home/trainee:/bin/sh
 </code> </code>
Ligne 252: Ligne 272:
  
 <code> <code>
-[trainee@centos7 ~]$ chsh+[trainee@centos8 ~]$ chsh
 Changing shell for trainee. Changing shell for trainee.
 New shell [/bin/sh]: /bin/bash New shell [/bin/sh]: /bin/bash
Ligne 275: Ligne 295:
  
 <code> <code>
-[trainee@centos7 ~]$ history | more+[trainee@centos8 ~]$ history | more
     1  su -     1  su -
-    2  df -h+    2  exit
     3  su -     3  su -
-    4  exit +    4  nmcli c show 
-    5  su +    5  stty -a 
-    6  su - +    6  date 
-    7  vi vitext +    7  who 
-    8  view vitext +    8  df 
-    9  vi vitext +    9  df -h 
-   10  locale +   10  free free -h 
-   11  LANG=en_GB.UTF-8 +   11  free 
-   12  export LANG +   12  free -h 
-   13  locale +   13  whoami 
-   14  vi vitext +   14  su - 
-   15  vi .exrc +   15  pwd 
-   16  vi vitext +   16  cd /tmp 
-   17  clear +   17  pwd 
-   18  stty -a +   18  ls 
-   19  date +   19  su - 
-   20  locale +   20  touch test 
-   21  who +   21  ls 
-   22  df +   22  echo fenestros 
-   23  df -h+   23  cp test ~
 --More-- --More--
 </code> </code>
Ligne 331: Ligne 351:
  
 <code> <code>
-[trainee@centos7 ~]$ ls +[trainee@centos8 ~]$ ls 
-aac  bca      Documents  Music     Public     Videos  xyz +aac  abc  bca  xyz 
-abc  Desktop  Downloads  Pictures  Templates  vitext +[trainee@centos8 ~]$ !!
-[trainee@centos7 ~]$ !!+
 ls ls
-aac  bca      Documents  Music     Public     Videos  xyz +aac  abc  bca  xyz
-abc  Desktop  Downloads  Pictures  Templates  vitext+
 </code> </code>
  
Ligne 343: Ligne 361:
  
 <code> <code>
-[trainee@centos7 ~]$ !123+[trainee@centos8 ~]$ history 
 +    1  su - 
 +... 
 +   80  history | more 
 +   81  ls 
 +   82  history 
 +[trainee@centos8 ~]$ !81
 ls ls
-aac  bca      Documents  Music     Public     Videos  xyz +aac  abc  bca  xyz
-abc  Desktop  Downloads  Pictures  Templates  vitext+
 </code> </code>
  
Ligne 352: Ligne 375:
  
 <code> <code>
-[trainee@centos7 ~]$ cat /etc/profile | grep HISTSIZE+[trainee@centos8 ~]$ cat /etc/profile | grep HISTSIZE
 HISTSIZE=1000 HISTSIZE=1000
 export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
Ligne 362: Ligne 385:
  
 <code> <code>
-[trainee@centos7 ~]$ nl .bash_history | more +[trainee@centos8 ~]$ nl .bash_history | tail 
-     1 su - +    54 ls 
-     2 df -h +    55 ls | sort 
-     3 su - +    56 ls | sort -r 
-     4 exit +    57 more /etc/services 
-     5 su - +    58 less /etc/services 
-     6 su - +    59 find acc 
-     7 vi vitext +    60 find aac 
-     8 view vitext +    61 su 
-     9 vi vitext +    62 sleep 10 
-    10 locale +    63 su -
-    11 LANG=en_GB.UTF-8 +
-    12 export LANG +
-    13 locale +
-    14 vi vitext +
-    15 vi .exrc +
-    16 vi vitext +
-    17 clear +
-    18 stty -a +
-    19 date +
-    20 locale +
-    21 who +
-    22 df +
-    23 df -h +
---More--+
 </code> </code>
  
Ligne 402: Ligne 411:
  
 <code> <code>
-[trainee@centos7 ~]$ ls .bash +[trainee@centos8 ~]$ ls .bash 
-.bash_history  .bash_logout   .bash_profile  .bashrc+.bash_history  .bash_logout   .bash_profile  .bashrc 
 </code> </code>
 +
 +<WRAP center round important 60%>
 +**Important** : Notez qu'en appuyant sur la touche <key>tab</key> trois fois le shell propose 4 possibilités de complétion de nom de fichier. En effet, sans plus d'information, le shell ne sait pas quel fichier est concerné.
 +</WRAP>
  
 This same technique can also be used to auto-generate command names. Consider the following example: This same technique can also be used to auto-generate command names. Consider the following example:
Ligne 413: Ligne 426:
  
 <code> <code>
-[trainee@centos7 ~]$ mo +[trainee@centos8 ~]$ mo 
-mobj_dump        modutil          mount.cifs       mount.nfs4       mousetweaks +modinfo                more                   mount.nfs4 
-modifyrepo       mokutil          mount.fuse       mountpoint        +modprobe               mount                  mountpoint 
-modinfo          more             mount.glusterfs  mountstats        +modulemd-validator     mount.fuse             mountstats 
-modprobe         mount            mount.nfs        mount.vboxsf +modulemd-validator-v1  mount.nfs 
 </code> </code>
  
Ligne 440: Ligne 453:
  
 <code> <code>
-[trainee@centos7 ~]$ mkdir training +[trainee@centos8 ~]$ mkdir training 
-[trainee@centos7 ~]$ cd training +[trainee@centos8 ~]$ cd training 
-[trainee@centos7 training]$ touch f1 f2 f3 f4 f5+[trainee@centos8 training]$ touch f1 f2 f3 f4 f5 
 +[trainee@centos8 training]$ ls 
 +f1  f2  f3  f4  f5
 </code> </code>
  
Ligne 450: Ligne 465:
  
 <code> <code>
-[trainee@centos7 training]$ echo f*+[trainee@centos8 training]$ echo f*
 f1 f2 f3 f4 f5 f1 f2 f3 f4 f5
 </code> </code>
Ligne 463: Ligne 478:
  
 <code> <code>
-[trainee@centos7 training]$ touch f52 f62+[trainee@centos8 training]$ touch f52 f62
 </code> </code>
  
Ligne 469: Ligne 484:
  
 <code> <code>
-[trainee@centos7 training]$ echo f?2+[trainee@centos8 training]$ echo f?2
 f52 f62 f52 f62
 </code> </code>
Ligne 490: Ligne 505:
  
 <code> <code>
-[trainee@centos7 training]$ touch a100+[trainee@centos8 training]$ touch a100
 </code> </code>
  
Ligne 496: Ligne 511:
  
 <code> <code>
-[trainee@centos7 training]$ echo [a-f]*+[trainee@centos8 training]$ echo [a-f]*
 a100 f1 f2 f3 f4 f5 f52 f62 a100 f1 f2 f3 f4 f5 f52 f62
-[trainee@centos7 training]$ echo [af]*+[trainee@centos8 training]$ echo [af]*
 a100 f1 f2 f3 f4 f5 f52 f62 a100 f1 f2 f3 f4 f5 f52 f62
 </code> </code>
Ligne 507: Ligne 522:
  
 <code> <code>
-[trainee@centos7 training]$ echo [!a]*+[trainee@centos8 training]$ echo [!a]*
 f1 f2 f3 f4 f5 f52 f62 f1 f2 f3 f4 f5 f52 f62
 </code> </code>
Ligne 516: Ligne 531:
  
 <code> <code>
-[trainee@centos7 training]$ echo [a-b]*+[trainee@centos8 training]$ echo [a-b]*
 a100 a100
 </code> </code>
Ligne 525: Ligne 540:
  
 <code> <code>
-[trainee@centos7 training]$ echo [a-f]+[trainee@centos8 training]$ echo [a-f]
 [a-f] [a-f]
 </code> </code>
Ligne 538: Ligne 553:
  
 <code> <code>
-[trainee@centos7 training]$ shopt -s extglob+[trainee@centos8 training]$ shopt -s extglob
 </code> </code>
  
Ligne 546: Ligne 561:
  
 <code> <code>
-[trainee@centos7 training]$ shopt+[trainee@centos8 training]$ shopt
 autocd          off autocd          off
 cdable_vars    off cdable_vars    off
Ligne 597: Ligne 612:
  
 <code> <code>
-[trainee@centos7 training]$ touch f f.txt f123.txt f123123.txt f123123123.txt+[trainee@centos8 training]$ touch f f.txt f123.txt f123123.txt f123123123.txt
 </code> </code>
  
Ligne 603: Ligne 618:
  
 <code> <code>
-[trainee@centos7 training]$ ls f?(123).txt+[trainee@centos8 training]$ ls f?(123).txt
 f123.txt  f.txt f123.txt  f.txt
 </code> </code>
Ligne 616: Ligne 631:
  
 <code> <code>
-[trainee@centos7 training]$ ls f*(123).txt+[trainee@centos8 training]$ ls f*(123).txt
 f123123123.txt  f123123.txt  f123.txt  f.txt f123123123.txt  f123123.txt  f123.txt  f.txt
 </code> </code>
Ligne 629: Ligne 644:
  
 <code> <code>
-[trainee@centos7 training]$ ls f+(123).txt+[trainee@centos8 training]$ ls f+(123).txt
 f123123123.txt  f123123.txt  f123.txt f123123123.txt  f123123.txt  f123.txt
 </code> </code>
Ligne 642: Ligne 657:
  
 <code> <code>
-[trainee@centos7 training]$ ls f@(123).txt+[trainee@centos8 training]$ ls f@(123).txt
 f123.txt f123.txt
 </code> </code>
Ligne 655: Ligne 670:
  
 <code> <code>
-[trainee@centos7 training]$ ls f!(123).txt+[trainee@centos8 training]$ ls f!(123).txt
 f123123123.txt  f123123.txt  f.txt f123123123.txt  f123123.txt  f.txt
 </code> </code>
Ligne 675: Ligne 690:
  
 <code> <code>
-[trainee@centos7 training]$ echo * est un caractère spécial+[trainee@centos8 training]$ echo * is a metacharacter
 a100 f f1 f123123123.txt f123123.txt f123.txt f2 f3 f4 f5 f52 f62 f.txt est un caractère spécial a100 f f1 f123123123.txt f123123.txt f123.txt f2 f3 f4 f5 f52 f62 f.txt est un caractère spécial
  
-[trainee@centos7 training]$ echo \* est un caractère spécial +[trainee@centos8 training]$ echo \* is a metacharacter 
-est un caractère spécial+is a metacharacter
  
-[trainee@centos7 training]$ echo "est un caractère spécial+[trainee@centos8 training]$ echo "is a metacharacter
-est un caractère spécial+is a metacharacter
  
-[trainee@centos7 training]$ echo 'est un caractère spécial+[trainee@centos8 training]$ echo 'is a metacharacter
-est un caractère spécial+is a metacharacter
 </code> </code>
  
Ligne 695: Ligne 710:
  
 <code> <code>
-[trainee@centos7 training]$ cd .. +[trainee@centos8 training]$ cd .. 
-[trainee@centos7 ~]$ mkdir codes +[trainee@centos8 ~]$ mkdir codes 
-[trainee@centos7 ~]$ echo $?+[trainee@centos8 ~]$ echo $?
 0 0
-[trainee@centos7 ~]$ touch codes/exit.txt +[trainee@centos8 ~]$ touch codes/exit.txt 
-[trainee@centos7 ~]$ rmdir codes+[trainee@centos8 ~]$ rmdir codes
 rmdir: failed to remove ‘codes’: Directory not empty rmdir: failed to remove ‘codes’: Directory not empty
-[trainee@centos7 ~]$ echo $?+[trainee@centos8 ~]$ echo $?
 1 1
 </code> </code>
  
-As you can see when the exit status is 0, the command has executed correctly. If the exit status is anything else, the command has executed with errors.+As you can see when the exit status is 0, the command has executed correctly. If the exit status is anything else, the command has executed with errors. 
  
 ====Redirections==== ====Redirections====
Ligne 719: Ligne 734:
  
 <code> <code>
-[trainee@centos7 ~]$ pwd+[trainee@centos8 ~]$ pwd
 /home/trainee /home/trainee
-[trainee@centos7 ~]$ cd training +[trainee@centos8 ~]$ cd training 
-[trainee@centos7 training]$ free > file +[trainee@centos8 training]$ free > file 
-[trainee@centos7 training]$ cat file+[trainee@centos8 training]$ cat file
               total        used        free      shared  buff/cache   available               total        used        free      shared  buff/cache   available
 Mem:         500780      192692       38916        4824      269172      260472 Mem:         500780      192692       38916        4824      269172      260472
Ligne 736: Ligne 751:
  
 <code> <code>
-[trainee@centos7 training]$ date > file +[trainee@centos8 training]$ date > file 
-[trainee@centos7 training]$ cat file+[trainee@centos8 training]$ cat file
 Mon 28 Nov 15:48:09 CET 2016 Mon 28 Nov 15:48:09 CET 2016
 </code> </code>
Ligne 744: Ligne 759:
  
 <code> <code>
-[trainee@centos7 training]$ free >> file +[trainee@centos8 training]$ free >> file 
-[trainee@centos7 training]$ cat file+[trainee@centos8 training]$ cat file
 Mon 28 Nov 15:48:09 CET 2016 Mon 28 Nov 15:48:09 CET 2016
               total        used        free      shared  buff/cache   available               total        used        free      shared  buff/cache   available
Ligne 765: Ligne 780:
  
 <code> <code>
-[trainee@centos7 training]$ cd .. +[trainee@centos8 training]$ cd .. 
-[trainee@centos7 ~]$ rmdir training/ 2>errorlog +[trainee@centos8 ~]$ rmdir training/ 2>errorlog 
-[trainee@centos7 ~]$ cat errorlog+[trainee@centos8 ~]$ cat errorlog
 rmdir: failed to remove ‘training/’: Directory not empty rmdir: failed to remove ‘training/’: Directory not empty
 </code> </code>
Ligne 778: Ligne 793:
  
 <code> <code>
-[trainee@centos7 ~]$ free > file 2>&1+[trainee@centos8 ~]$ free > file 2>&1
 </code> </code>
  
Ligne 786: Ligne 801:
  
 <code> <code>
-[trainee@centos7 ~]$ wc -w < errorlog+[trainee@centos8 ~]$ wc -w < errorlog
 8 8
 </code> </code>
Ligne 801: Ligne 816:
 ====Pipes==== ====Pipes====
  
-A pipe is used to present the standard output on the first command to the standard input of the second command:+A pipe is used to present the standard output on the first command to the standard input of the second command
  
 <code> <code>
-[trainee@centos7 ~]$ ls | wc -w +[trainee@centos8 ~]$ ls | wc -w 
-17+7
 </code> </code>
  
Ligne 812: Ligne 827:
 </WRAP> </WRAP>
  
-Standard output can generally only be redirected to a single destination. To redirect to two destinations at once, you need to use the **tee** command:+Standard output can generaly only be redirected to a single destination. To redirect to two destinations at once, you need to use the **tee** command:
  
 <code> <code>
-[trainee@centos7 ~]$ date | tee file1 +[trainee@centos8 ~]$ date | tee file1 
-Mon 28 Nov 16:14:24 CET 2016 +Tue 20 Apr 10:39:47 EDT 2021 
-[trainee@centos7 ~]$ cat file1 +[trainee@centos8 ~]$ cat file1 
-Mon 28 Nov 16:14:24 CET 2016+Tue 20 Apr 10:39:47 EDT 2021
 </code> </code>
  
Ligne 824: Ligne 839:
  
 <code> <code>
-[trainee@centos7 ~]$ date | tee file1 > file2 +[trainee@centos8 ~]$ date | tee file1 > file2 
-[trainee@centos7 ~]$ cat file1 +[trainee@centos8 ~]$ cat file1 
-Mon 28 Nov 16:15:57 CET 2016 +Tue 20 Apr 10:40:36 EDT 2021 
-[trainee@centos7 ~]$ cat file2 +[trainee@centos8 ~]$ cat file2 
-Mon 28 Nov 16:15:57 CET 2016+Tue 20 Apr 10:40:36 EDT 2021
 </code> </code>
  
Ligne 840: Ligne 855:
  
 <code> <code>
-[trainee@centos7 ~]$ echo date+[trainee@centos8 ~]$ echo date
 date date
-[trainee@centos7 ~]$ echo $(date) +[trainee@centos8 ~]$ echo $(date) 
-Mon 28 Nov 16:19:35 CET 2016 +Tue 20 Apr 10:41:33 EDT 2021 
-[trainee@centos7 ~]$ echo `date` +[trainee@centos8 ~]$ echo `date` 
-Mon 28 Nov 16:19:35 CET 2016+Tue 20 Apr 10:41:45 EDT 2021
 </code> </code>
  
Ligne 852: Ligne 867:
 Commands can be grouped using brackets: Commands can be grouped using brackets:
  
-<code> +  $ (ls -l; ps; who) > list [Entrée]
-$ (ls -l; ps; who) > list +
-</code>+
  
 Conditional command execution can be obtained by using the exit status value and either **&&** or **||**. Conditional command execution can be obtained by using the exit status value and either **&&** or **||**.
Ligne 931: Ligne 944:
  
 <code> <code>
-[trainee@centos7 ~]$ echo $LC_ALL +[trainee@centos8 ~]$ echo $LC_ALL
-en_GB.UTF-8 +
-[trainee@centos7 ~]$ echo $LC_CTYPE+
  
-[trainee@centos7 ~]$ echo $LANG +[trainee@centos8 ~]$ echo $LC_CTYPE
-en_GB.UTF-8 +
  
-[trainee@centos7 ~]$ locale+[trainee@centos8 ~]$ echo $LANG 
 +en_GB.UTF-8 
 +[trainee@centos8 ~]$ locale
 LANG=en_GB.UTF-8 LANG=en_GB.UTF-8
 LC_CTYPE="en_GB.UTF-8" LC_CTYPE="en_GB.UTF-8"
Ligne 952: Ligne 964:
 LC_MEASUREMENT="en_GB.UTF-8" LC_MEASUREMENT="en_GB.UTF-8"
 LC_IDENTIFICATION="en_GB.UTF-8" LC_IDENTIFICATION="en_GB.UTF-8"
-LC_ALL=en_GB.UTF-8+LC_ALL=
 </code> </code>
  
Ligne 967: Ligne 979:
 | $@ | Contains all of the arguments passed to the script | | $@ | Contains all of the arguments passed to the script |
  
-====The env Commande====+====The env Command====
  
-The **env** command can be used to run a program in a modified environment or just list the values of all environmental variables associated with the user calling the program env: +The **env** command can be used to run a program in a modified environment or just list the values of all environmental variables associated with the user calling the program env:
  
 <code> <code>
-[trainee@centos7 ~]$ env +[trainee@centos8 ~]$ env 
-XDG_SESSION_ID=1 +LS_COLORS=rs=0:di=38;5;33:ln=38;5;51:mh=00:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=01;05;37;41:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;40:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lz4=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.zst=38;5;9:*.tzst=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.wim=38;5;9:*.swm=38;5;9:*.dwm=38;5;9:*.esd=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.mjpg=38;5;13:*.mjpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.webm=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.m4a=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.oga=38;5;45:*.opus=38;5;45:*.spx=38;5;45:*.xspf=38;5;45: 
-HOSTNAME=centos7.fenestros.loc+SSH_CONNECTION=10.0.2.2 42834 10.0.2.15 22 
 +LANG=en_GB.UTF-8 
 +HISTCONTROL=ignoredups 
 +GUESTFISH_RESTORE=\e[0m 
 +HOSTNAME=centos8.ittraining.loc 
 +GUESTFISH_INIT=\e[1;34m 
 +XDG_SESSION_ID=9 
 +USER=trainee 
 +GUESTFISH_PS1=\[\e[1;32m\]><fs>\[\e[0;31m\] 
 SELINUX_ROLE_REQUESTED= SELINUX_ROLE_REQUESTED=
 +PWD=/home/trainee
 +HOME=/home/trainee
 +SSH_CLIENT=10.0.2.2 42834 22
 +SELINUX_LEVEL_REQUESTED=
 +SSH_TTY=/dev/pts/0
 +MAIL=/var/spool/mail/trainee
 TERM=xterm-256color TERM=xterm-256color
 SHELL=/bin/bash SHELL=/bin/bash
-HISTSIZE=1000 
-SSH_CLIENT=10.0.2.2 33896 22 
 SELINUX_USE_CURRENT_RANGE= SELINUX_USE_CURRENT_RANGE=
-SSH_TTY=/dev/pts/0 
-LC_ALL=en_GB.UTF-8 
-USER=trainee 
-LS_COLORS=rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lz4=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.webm=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45: 
-MAIL=/var/spool/mail/trainee 
-PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/trainee/.local/bin:/home/trainee/bin 
-PWD=/home/trainee 
-LANG=fr_FR.UTF-8 
-SELINUX_LEVEL_REQUESTED= 
-HISTCONTROL=ignoredups 
 SHLVL=1 SHLVL=1
-HOME=/home/trainee 
 LOGNAME=trainee LOGNAME=trainee
-SSH_CONNECTION=10.0.2.2 33896 192.168.1.99 22 +DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
-LESSOPEN=||/usr/bin/lesspipe.sh %s+
 XDG_RUNTIME_DIR=/run/user/1000 XDG_RUNTIME_DIR=/run/user/1000
 +PATH=/home/trainee/.local/bin:/home/trainee/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
 +GUESTFISH_OUTPUT=\e[0m
 +HISTSIZE=1000
 +LESSOPEN=||/usr/bin/lesspipe.sh %s
 _=/usr/bin/env _=/usr/bin/env
 OLDPWD=/home/trainee/training OLDPWD=/home/trainee/training
Ligne 1010: Ligne 1026:
  
 <code> <code>
-[trainee@centos7 ~]$ set -o+[trainee@centos8 ~]$ set -o
 allexport      off allexport      off
 braceexpand    on braceexpand    on
Ligne 1043: Ligne 1059:
  
 <code> <code>
-[trainee@centos7 ~]$ set -o allexport +[trainee@centos8 ~]$ set -o allexport 
-[trainee@centos7 ~]$ set -o+[trainee@centos8 ~]$ set -o
 allexport      on allexport      on
 braceexpand    on braceexpand    on
Ligne 1051: Ligne 1067:
  
 To turn off an option, use set with the **+o** option: To turn off an option, use set with the **+o** option:
- 
 <code> <code>
-[trainee@centos7 ~]$ set +o allexport +[trainee@centos8 ~]$ set +o allexport 
-[trainee@centos7 ~]$ set -o+[trainee@centos8 ~]$ set -o
 allexport      off allexport      off
 braceexpand    on braceexpand    on
Ligne 1074: Ligne 1089:
  
 <code> <code>
-[trainee@centos7 ~]$ set -o noclobber +[trainee@centos8 ~]$ set -o noclobber 
-[trainee@centos7 ~]$ pwd > file+[trainee@centos8 ~]$ pwd > file
 -bash: file: cannot overwrite existing file -bash: file: cannot overwrite existing file
-[trainee@centos7 ~]$ pwd > file+[trainee@centos8 ~]$ pwd > file
 -bash: file: cannot overwrite existing file -bash: file: cannot overwrite existing file
-[trainee@centos7 ~]$ pwd >| file +[trainee@centos8 ~]$ pwd >| file 
-[trainee@centos7 ~]$ set +o noclobber+[trainee@centos8 ~]$ set +o noclobber
 </code> </code>
  
Ligne 1090: Ligne 1105:
  
 <code> <code>
-[trainee@centos7 ~]$ set -o noglob +[trainee@centos8 ~]$ set -o noglob 
-[trainee@centos7 ~]$ echo *+[trainee@centos8 ~]$ echo *
 * *
-[trainee@centos7 ~]$ set +o noglob +[trainee@centos8 ~]$ set +o noglob 
-[trainee@centos7 ~]$ echo *+[trainee@centos8 ~]$ echo *
 aac abc bca codes Desktop Documents Downloads errorlog file file1 Music Pictures Public Templates training Videos vitext xyz aac abc bca codes Desktop Documents Downloads errorlog file file1 Music Pictures Public Templates training Videos vitext xyz
 </code> </code>
Ligne 1105: Ligne 1120:
  
 <code> <code>
-[trainee@centos7 ~]$ set -o nounset +[trainee@centos8 ~]$ set -o nounset 
-[trainee@centos7 ~]$ echo $FENESTROS+[trainee@centos8 ~]$ echo $FENESTROS
 -bash: FENESTROS: unbound variable -bash: FENESTROS: unbound variable
-[trainee@centos7 ~]$ set +o nounset +[trainee@centos8 ~]$ set +o nounset 
-[trainee@centos7 ~]$ echo $FENESTROS+[trainee@centos8 ~]$ echo $FENESTROS
  
-[trainee@centos7 ~]$ +[trainee@centos8 ~]$ 
 </code> </code>
  
Ligne 1151: Ligne 1166:
  
 <code> <code>
-[trainee@centos7 ~]$ script+[trainee@centos8 ~]$ script
 Script started, file is typescript Script started, file is typescript
-[trainee@centos7 ~]$ pwd+[trainee@centos8 ~]$ pwd
 /home/trainee /home/trainee
-[trainee@centos7 ~]$ ls +[trainee@centos8 ~]$ ls 
-aac  bca    Desktop    Downloads  fichier1  file   Music     Public     training    Videos  xyz +aac  abc  bca  codes  errorlog  file  file1  file2  training  typescript  xyz 
-abc  codes  Documents  errorlog   fichier2  file1  Pictures  Templates  typescript  vitext +[trainee@centos8 ~]$ exit
-[trainee@centos7 ~]$ exit+
 exit exit
 Script done, file is typescript Script done, file is typescript
-[trainee@centos7 ~]$ cat typescript  + 
-Script started on Tue 29 Nov 2016 03:58:33 CET +[trainee@centos8 ~]$ cat typescript  
-[trainee@centos7 ~]$ pwd+Script started on 2021-04-20 10:59:58-04:00 
 +[trainee@centos8 ~]$ pwd
 /home/trainee /home/trainee
-[trainee@centos7 ~]$ ls +[trainee@centos8 ~]$ ls 
-aac  bca    Desktop    Downloads  fichier1  file   Music     Public     training    Videos  xyz +aac  abc  bca  codes  errorlog  file  file1  file2  training  typescript  xyz 
-abc  codes  Documents  errorlog   fichier2  file1  Pictures  Templates  typescript  vitext +[trainee@centos8 ~]$ exit
-[trainee@centos7 ~]$ exit+
 exit exit
  
-Script done on Tue 29 Nov 2016 03:58:40 CET+Script done on 2021-04-20 11:00:09-04:00
 </code> </code>
  
 Lets start by creating a simple script called **myscript**: Lets start by creating a simple script called **myscript**:
- 
-  $ vi myscript [Enter] 
- 
-Edit the file as follows: 
  
 <code> <code>
 +[trainee@centos8 ~]$ vi myscript
 +[trainee@centos8 ~]$ cat myscript
 pwd pwd
 ls ls
 </code> </code>
- 
-<WRAP center round important 60%> 
-**Important**: Note that in the above example, the script does not start with a pseudo-comment. As a result, the script will be executed by the shell of the user that invokes it unless a different shell is specified. 
-</WRAP> 
  
 Save the file and use the five ways to execute it. Save the file and use the five ways to execute it.
Ligne 1194: Ligne 1202:
  
 <code> <code>
-[trainee@centos7 ~]$ vi myscript +[trainee@centos8 ~]$ /bin/bash myscript
-[trainee@centos7 ~]$ /bin/bash myscript+
 /home/trainee /home/trainee
-aac  codes Downloads  fichier2  myscript Public    typescript  xyz +aac  bca    errorlog  file1  myscript  typescript 
-abc  Desktop errorlog   file      Music Templates  Videos +abc  codes  file      file2  training  xyz
-bca  Documents fichier1   file1     Pictures training   vitext+
 </code> </code>
  
Ligne 1205: Ligne 1211:
  
 <code> <code>
-[trainee@centos7 ~]$ /bin/bash < myscript+[trainee@centos8 ~]$ /bin/bash < myscript
 /home/trainee /home/trainee
-aac  codes Downloads  fichier2  myscript Public    typescript  xyz +aac  bca    errorlog  file1  myscript  typescript 
-abc  Desktop errorlog   file      Music Templates  Videos +abc  codes  file      file2  training  xyz
-bca  Documents fichier1   file1     Pictures training   vitext+
 </code> </code>
  
Ligne 1215: Ligne 1220:
  
 <code> <code>
-[trainee@centos7 ~]$ echo $PATH +[trainee@centos8 ~]$ echo $PATH 
-/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/trainee/.local/bin:/home/trainee/bin+/home/trainee/.local/bin:/home/trainee/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
 </code> </code>
  
Ligne 1222: Ligne 1227:
  
 <code> <code>
-[trainee@centos7 ~]$ ls +[trainee@centos8 ~]$ ls 
-aac  codes      Downloads  fichier2  myscript  Public     typescript  xyz +aac  bca    errorlog  file1  myscript  typescript 
-abc  Desktop    errorlog   file      Music      Templates  Videos +abc  codes  file      file2  training  xyz
-bca  Documents  fichier1   file1     Pictures   training   vitext+
 </code> </code>
  
Ligne 1231: Ligne 1235:
  
 <code> <code>
-[trainee@centos7 ~]$ mkdir bin+[trainee@centos8 ~]$ mkdir bin
 </code> </code>
  
Ligne 1237: Ligne 1241:
  
 <code> <code>
-[trainee@centos7 ~]$ mv myscript ~/bin +[trainee@centos8 ~]$ mv myscript ~/bin 
-[trainee@centos7 ~]$ chmod u+x ~/bin/myscript+[trainee@centos8 ~]$ chmod u+x ~/bin/myscript
 </code> </code>
  
Ligne 1244: Ligne 1248:
  
 <code> <code>
-[trainee@centos7 tmp]$ myscript+[trainee@centos8 ~]$ cd /tmp 
 +[trainee@centos8 tmp]$ myscript
 /tmp /tmp
-hsperfdata_root  systemd-private-e526abcf335b40949dfc725f28456502-cups.service-u0xGiL+expand 
 +expand1 
 +filepartaa 
 +filepartab 
 +filepartac 
 +filepartad 
 +filepartae 
 +greptest 
 +greptest1 
 +greptest.patch 
 +newfile 
 +sales.awk 
 +sales.txt 
 +scriptawk 
 +sedtest 
 +sedtest1 
 +systemd-private-d9ff2376a8a44f0392f860d80c839be4-chronyd.service-6im4Ii
 </code> </code>
  
 Now move back to ~/bin and use the following two commands to execute myscript: Now move back to ~/bin and use the following two commands to execute myscript:
- 
-  * ./myscript 
-  * . myscript 
  
 <code> <code>
-[trainee@centos7 tmp]$ cd ~/bin +[trainee@centos8 tmp]$ cd ~/bin 
-[trainee@centos7 bin]$ ./myscript +[trainee@centos8 bin]$ ./myscript
 /home/trainee/bin /home/trainee/bin
 myscript myscript
-[trainee@centos7 bin]$ . myscript +[trainee@centos8 bin]$ . myscript
 /home/trainee/bin /home/trainee/bin
 myscript myscript
Ligne 1273: Ligne 1291:
  
 <code> <code>
-[trainee@centos7 bin]$ read var1 var2 var3 var4+[trainee@centos8 bin]$ read var1 var2 var3 var4
 fenestros edu is great! fenestros edu is great!
-[trainee@centos7 bin]$ echo $var1+[trainee@centos8 bin]$ echo $var1
 fenestros fenestros
-[trainee@centos7 bin]$ echo $var2+[trainee@centos8 bin]$ echo $var2
 edu edu
-[trainee@centos7 bin]$ echo $var3+[trainee@centos8 bin]$ echo $var3
 is is
-[trainee@centos7 bin]$ echo $var4+[trainee@centos8 bin]$ echo $var4
 great! great!
 </code> </code>
Ligne 1290: Ligne 1308:
  
 <code> <code>
-[trainee@centos7 bin]$ read var1 var2+[trainee@centos8 bin]$ read var1 var2
 fenestros edu is great! fenestros edu is great!
-[trainee@centos7 bin]$ echo $var1+[trainee@centos8 bin]$ echo $var1
 fenestros fenestros
-[trainee@centos7 bin]$ echo $var2+[trainee@centos8 bin]$ echo $var2
 edu is great! edu is great!
 </code> </code>
Ligne 1302: Ligne 1320:
 </WRAP> </WRAP>
  
-===Code de retour===+===Exit Codes===
  
 The contents of a variable can also be empty: The contents of a variable can also be empty:
  
 <code> <code>
-[trainee@centos7 bin]$ read var+[trainee@centos8 bin]$ read var
 </code> </code>
-<key>Enter</key>+<key>Entrée</key>
 <code> <code>
-[trainee@centos7 bin]$ echo $?+[trainee@centos8 bin]$ echo $?
 0 0
-[trainee@centos7 bin]$ echo $var+[trainee@centos8 bin]$ echo $var
  
-[trainee@centos7 bin]$ +[trainee@centos8 bin]$ 
 </code> </code>
  
Ligne 1321: Ligne 1339:
  
 <code> <code>
-[trainee@centos7 bin]$ read var+[trainee@centos8 bin]$ read var
 </code> </code>
 <key>C-d</key> <key>C-d</key>
 <code> <code>
-[trainee@centos7 bin]$ echo $?+[trainee@centos8 bin]$ echo $?
 1 1
-[trainee@centos7 bin]$ echo $var+[trainee@centos8 bin]$ echo $var
  
-[trainee@centos7 bin]$ +[trainee@centos8 bin]$ 
 </code> </code>
  
Ligne 1337: Ligne 1355:
  
 <code> <code>
-[trainee@centos7 bin]$ echo "$IFS" | od -c+[trainee@centos8 bin]$ echo "$IFS" | od -c
 0000000      \t  \n  \n 0000000      \t  \n  \n
 0000004 0000004
Ligne 1349: Ligne 1367:
  
 <code> <code>
-[trainee@centos7 bin]$ OLDIFS="$IFS" +[trainee@centos8 bin]$ OLDIFS="$IFS" 
-[trainee@centos7 bin]$ IFS=":" +[trainee@centos8 bin]$ IFS=":" 
-[trainee@centos7 bin]$ echo "$IFS" | od -c+[trainee@centos8 bin]$ echo "$IFS" | od -c
 0000000   :  \n 0000000   :  \n
 0000002 0000002
Ligne 1359: Ligne 1377:
  
 <code> <code>
-[trainee@centos7 bin]$ read var1 var2 var3+[trainee@centos8 bin]$ read var1 var2 var3
 fenestros:edu is:great! fenestros:edu is:great!
-[trainee@centos7 bin]$ echo $var1+[trainee@centos8 bin]$ echo $var1
 fenestros fenestros
-[trainee@centos7 bin]$ echo $var2+[trainee@centos8 bin]$ echo $var2
 edu is edu is
-[trainee@centos7 bin]$ echo $var3+[trainee@centos8 bin]$ echo $var3
 great! great!
 </code> </code>
Ligne 1372: Ligne 1390:
  
 <code> <code>
-[trainee@centos7 bin]$ IFS="$OLDIFS" +[trainee@centos8 bin]$ IFS="$OLDIFS" 
-[trainee@centos7 bin]$ echo "$IFS" | od -c+[trainee@centos8 bin]$ echo "$IFS" | od -c
 0000000      \t  \n  \n 0000000      \t  \n  \n
 0000004 0000004
Ligne 1401: Ligne 1419:
 | file1 -ot file2 | Returns true if file1 is older than file2 | | file1 -ot file2 | Returns true if file1 is older than file2 |
 | file1 -ef file2 | Returns true if file1 is identical to file2 | | file1 -ef file2 | Returns true if file1 is identical to file2 |
- 
-==LAB #1== 
  
 Test whether the **a100** file is an ordinary file: Test whether the **a100** file is an ordinary file:
  
 <code> <code>
-[trainee@centos7 bin]$ cd ../training/ +[trainee@centos8 bin]$ cd ../training/ 
-[trainee@centos7 training]$ test -f a100 +[trainee@centos8 training]$ test -f a100 
-[trainee@centos7 training]$ echo $? +[trainee@centos8 training]$ echo $? 
 0 0
-[trainee@centos7 training]$ [ -f a100 ] +[trainee@centos8 training]$ [ -f a100 ] 
-[trainee@centos7 training]$ echo $? +[trainee@centos8 training]$ echo $? 
 0 0
 </code> </code>
Ligne 1423: Ligne 1439:
  
 <code> <code>
-[trainee@centos7 training]$ [ -f a101 ] +[trainee@centos8 training]$ [ -f a101 ] 
-[trainee@centos7 training]$ echo $?+[trainee@centos8 training]$ echo $?
 1 1
 </code> </code>
Ligne 1435: Ligne 1451:
  
 <code> <code>
-[trainee@centos7 training]$ [ -d /home/trainee/training ] +[trainee@centos8 training]$ [ -d /home/trainee/training ] 
-[trainee@centos7 training]$ echo $?+[trainee@centos8 training]$ echo $?
 0 0
 </code> </code>
- 
-<WRAP center round important 60%> 
-**Important**: The value contained in $? is 0. This indicates **true**. 
-</WRAP> 
  
 ===Testing Strings=== ===Testing Strings===
Ligne 1452: Ligne 1464:
 | string1 != string2 | Returns true if string1 is different to string2 | | string1 != string2 | Returns true if string1 is different to string2 |
 | string1 | Returns true if string1 is not empty | | string1 | Returns true if string1 is not empty |
- 
-==LAB #2== 
  
 Test whether two strings are indentical: Test whether two strings are indentical:
  
 <code> <code>
-[trainee@centos7 training]$ string1="root" +[trainee@centos8 training]$ string1="root" 
-[trainee@centos7 training]$ string2="fenestros" +[trainee@centos8 training]$ string2="fenestros" 
-[trainee@centos7 training]$ [ $string1 = $string2 ] +[trainee@centos8 training]$ [ $string1 = $string2 ] 
-[trainee@centos7 training]$ echo $?+[trainee@centos8 training]$ echo $?
 1 1
 </code> </code>
Ligne 1472: Ligne 1482:
  
 <code> <code>
-[trainee@centos7 training]$ [ -n $string1 ] +[trainee@centos8 training]$ [ -n $string1 ] 
-[trainee@centos7 training]$ echo $?+[trainee@centos8 training]$ echo $?
 0 0
-</code> 
- 
-<WRAP center round important 60%> 
-**Important**: The value contained in $? is 0. This indicates **true**. 
-</WRAP> 
- 
-Test if string1 is is zero in length: 
- 
-<code> 
-[trainee@centos7 training]$ [ -z $string1 ] 
-[trainee@centos7 training]$ echo $? 
-1 
 </code> </code>
  
Ligne 1503: Ligne 1501:
 | value1 -ge value2 | Returns true if value1 is greater than or equal to value2 | | value1 -ge value2 | Returns true if value1 is greater than or equal to value2 |
  
-==LAB #3== +Compare the two numbers **value1** and **value2**:
- +
-Compare the two numbers **value1** and **value2** :+
  
 <code> <code>
-[trainee@centos7 training]$ read value1+[trainee@centos8 training]$ read value1
 35 35
-[trainee@centos7 training]$ read value2+[trainee@centos8 training]$ read value2
 23 23
-[trainee@centos7 training]$ [ $value1 -lt $value2 ] +[trainee@centos8 training]$ [ $value1 -lt $value2 ] 
-[trainee@centos7 training]$ echo $?+[trainee@centos8 training]$ echo $?
 1 1
-[trainee@centos7 training]$ [ $value2 -lt $value1 ] +[trainee@centos8 training]$ [ $value2 -lt $value1 ] 
-[trainee@centos7 training]$ echo $?+[trainee@centos8 training]$ echo $?
 0 0
-[trainee@centos7 training]$ [ $value2 -eq $value1 ] +[trainee@centos8 training]$ [ $value2 -eq $value1 ] 
-[trainee@centos7 training]$ echo $?+[trainee@centos8 training]$ echo $?
 1 1
 </code> </code>
Ligne 1530: Ligne 1526:
 | expression1 -o expression2 | Represents a logical AND between expression1 and expression2 | | expression1 -o expression2 | Represents a logical AND between expression1 and expression2 |
 | \(expression\) | Parenthesis let you group together expressions  | | \(expression\) | Parenthesis let you group together expressions  |
- 
-==LAB #4== 
  
 Test if $file is not a directory: Test if $file is not a directory:
  
 <code> <code>
-[trainee@centos7 training]$ file=a1OO +[trainee@centos8 training]$ file=a1OO 
-[trainee@centos7 training]$ [ ! -d $file ] +[trainee@centos8 training]$ [ ! -d $file ] 
-[trainee@centos7 training]$ echo $?+[trainee@centos8 training]$ echo $?
 0 0
 </code> </code>
Ligne 1545: Ligne 1539:
  
 <code> <code>
-[trainee@centos7 training]$ directory=/usr +[trainee@centos8 training]$ directory=/usr 
-[trainee@centos7 training]$ [ -d $directory -a -x $directory ] +[trainee@centos8 training]$ [ -d $directory -a -x $directory ] 
-[trainee@centos7 training]$ echo $?+[trainee@centos8 training]$ echo $?
 0 0
 </code> </code>
Ligne 1554: Ligne 1548:
  
 <code> <code>
-[trainee@centos7 training]$ [ -w a100 -a \( -d /usr -o -d /tmp \) ] +[trainee@centos8 training]$ [ -w a100 -a \( -d /usr -o -d /tmp \) ] 
-[trainee@centos7 training]$ echo $?+[trainee@centos8 training]$ echo $?
 0 0
 </code> </code>
Ligne 1563: Ligne 1557:
 ^ Test ^ Description ^ ^ Test ^ Description ^
 | -o option | Returns true if the shell option "option" is on | | -o option | Returns true if the shell option "option" is on |
- 
-==LAB #5== 
  
 <code> <code>
Ligne 1588: Ligne 1580:
 | string1 < string2 | Returns true if string1 is lexicographically before string2 | | string1 < string2 | Returns true if string1 is lexicographically before string2 |
 | string1 > string2 | Returns true if string1 is lexicographically after string2  | | string1 > string2 | Returns true if string1 is lexicographically after string2  |
- 
-===LAB #6=== 
  
 Test if trainee has the write permission for the a100 file **and** test if /usr is a directory **or** test if /tmp is a directory: Test if trainee has the write permission for the a100 file **and** test if /usr is a directory **or** test if /tmp is a directory:
  
 <code> <code>
-[trainee@centos7 training]$ [[ -w a100 && ( -d /usr || -d /tmp ) ]] +[trainee@centos8 training]$ [[ -w a100 && ( -d /usr || -d /tmp ) ]] 
-[trainee@centos7 training]$ echo $?+[trainee@centos8 training]$ echo $?
 0 0
 </code> </code>
Ligne 1604: Ligne 1594:
 | Command1 %%&&%% Command2 | Command2 is executed if the exit code of Command1 is zero| | Command1 %%&&%% Command2 | Command2 is executed if the exit code of Command1 is zero|
 | Command1 %%||%% Command2 | Command2 is executed is the exit code of Command1 is not zero | | Command1 %%||%% Command2 | Command2 is executed is the exit code of Command1 is not zero |
- 
-===LAB #7=== 
  
 <code> <code>
-[trainee@centos7 training]$ [[ -d /root ]] && echo "The root directory exists"+[trainee@centos8 training]$ [[ -d /root ]] && echo "The root directory exists"
 The root directory exists The root directory exists
-[trainee@centos7 training]$ [[ -d /root ]] || echo "The root directory exists" +[trainee@centos8 training]$ [[ -d /root ]] || echo "The root directory exists" 
-[trainee@centos7 training]$  +[trainee@centos8 training]$  
 </code> </code>
  
Ligne 1657: Ligne 1645:
 | %%\|%% | Logical OR | | %%\|%% | Logical OR |
 | \& | Logical AND | | \& | Logical AND |
- 
-==LAB #8== 
  
 Add two to the value of $x: Add two to the value of $x:
  
 <code> <code>
-[trainee@centos7 training]$ x=2 +[trainee@centos8 training]$ x=2 
-[trainee@centos7 training]$ expr $x + 2+[trainee@centos8 training]$ expr $x + 2
 4 4
 </code> </code>
Ligne 1671: Ligne 1657:
  
 <code> <code>
-[trainee@centos7 training]$ expr $x+2+[trainee@centos8 training]$ expr $x+2
 2+2 2+2
 </code> </code>
Ligne 1678: Ligne 1664:
  
 <code> <code>
-[trainee@centos7 training]$ expr $x * 2+[trainee@centos8 training]$ expr $x * 2
 expr: syntax error expr: syntax error
-[trainee@centos7 training]$ expr $x \* 2+[trainee@centos8 training]$ expr $x \* 2
 4 4
 </code> </code>
Ligne 1687: Ligne 1673:
  
 <code> <code>
-[trainee@centos7 training]$ resultat=`expr $x + 10` +[trainee@centos8 training]$ resultat=`expr $x + 10` 
-[trainee@centos7 training]$ echo $resultat+[trainee@centos8 training]$ echo $resultat
 12 12
 </code> </code>
Ligne 1740: Ligne 1726:
 | %%^%% | Exclusive binary OR | | %%^%% | Exclusive binary OR |
  
-==LAB #9==+For example:
  
 <code> <code>
-[trainee@centos7 training]$ x=2 +[trainee@centos8 training]$ x=2 
-[trainee@centos7 training]$ ((x=$x+10)) +[trainee@centos8 training]$ ((x=$x+10)) 
-[trainee@centos7 training]$ echo $x+[trainee@centos8 training]$ echo $x
 12 12
-[trainee@centos7 training]$ ((x=$x+20)) +[trainee@centos8 training]$ ((x=$x+20)) 
-[trainee@centos7 training]$ echo $x+[trainee@centos8 training]$ echo $x
 32 32
 </code> </code>
Ligne 1794: Ligne 1780:
 fi fi
 </file> </file>
 +
 +As an example, create the following script called **user_check**:
 +
 +<code>
 +[trainee@centos8 training]$ vi user_check
 +[trainee@centos8 training]$ cat user_check
 +#!/bin/bash
 +if [ $# -ne 1 ] ; then
 +  echo "Incorrect number of arguments"
 +  echo "Usage : $0 user name"
 +  exit 1
 +fi
 +if grep "^$1:" /etc/passwd > /dev/null
 +then
 +  echo "User $1 has an account on this system"
 +else
 +  echo "User $1 does not have an account on this system"
 +fi
 +exit 0
 +</code>
 +
 +Test this script:
 +
 +<code>
 +[trainee@centos8 training]$ chmod 770 user_check
 +[trainee@centos8 training]$ ./user_check
 +Incorrect number of arguments
 +Usage : ./user_check user name
 +[trainee@centos8 training]$ ./user_check root
 +User root has an account on this system
 +[trainee@centos8 training]$ ./user_check mickey mouse
 +Incorrect number of arguments
 +Usage : ./user_check user name
 +[trainee@centos8 training]$ ./user_check "mickey mouse"
 +User mickey mouse does not have an account on this system
 +</code>
  
 ===case=== ===case===
Ligne 1812: Ligne 1834:
 esac esac
 </file> </file>
 +
 +For example:
 +
 +<code>
 +  case "$1" in
 +      start)
 +          start
 +          ;;
 +      stop)
 +          stop
 +          ;;
 +      restart|reload)
 +          stop
 +          start
 +          ;;
 +      status)
 +          status
 +          ;;
 +      *)
 +          echo $"Usage: $0 {start|stop|restart|status}"
 +          exit 1
 +esac
 +</code>
  
 ====Loops==== ====Loops====
  
 ===for=== ===for===
- 
  
 The syntax is as follows: The syntax is as follows:
Ligne 1826: Ligne 1870:
 done done
 </file> </file>
- 
  
 ===while=== ===while===
Ligne 1847: Ligne 1890:
 useradd fenestros"$U" -c fenestros"$U" -d /home/fenestros"$U" -g staff -G audio,fuse -s /bin/bash 2>/dev/null useradd fenestros"$U" -c fenestros"$U" -d /home/fenestros"$U" -g staff -G audio,fuse -s /bin/bash 2>/dev/null
 useradd fenestros"$U"$ -g machines -s /dev/false -d /dev/null 2>/dev/null useradd fenestros"$U"$ -g machines -s /dev/false -d /dev/null 2>/dev/null
-echo "Compte fenestros$U créé"+echo "Account fenestros$U created"
 let U=U+1 let U=U+1
 done done
Ligne 1863: Ligne 1906:
 When a login shell is terminated, Bash executes the **~/.bash_logout** file if it exists. When a login shell is terminated, Bash executes the **~/.bash_logout** file if it exists.
  
-Whan Bash is called as an interactive shell as opposed to a login shell, it executes only the **~/.bashrc** file.+Whan Bash is called as an interactive shell as opposed to a login shell, it executes only the **~/.bashrc** file
  
-====LAB #11====+====LAB #1 - Start-up Scripts====
  
 <WRAP center round important 60%> <WRAP center round important 60%>
Ligne 1871: Ligne 1914:
 </WRAP> </WRAP>
  
-===~~/.bash_profile===+===~/.bash_profile===
  
 <code> <code>
-[trainee@centos7 training]$ cat ~/.bash_profile+[trainee@centos8 training]$ cat ~/.bash_profile
 # .bash_profile # .bash_profile
  
Ligne 1883: Ligne 1926:
  
 # User specific environment and startup programs # User specific environment and startup programs
- 
-PATH=$PATH:$HOME/.local/bin:$HOME/bin 
- 
-export PATH 
 </code> </code>
  
Ligne 1892: Ligne 1931:
  
 <code> <code>
-[trainee@centos7 training]$ cat ~/.bashrc+[trainee@centos8 training]$ cat ~/.bashrc
 # .bashrc # .bashrc
  
Ligne 1899: Ligne 1938:
  . /etc/bashrc  . /etc/bashrc
 fi fi
 +
 +# User specific environment
 +PATH="$HOME/.local/bin:$HOME/bin:$PATH"
 +export PATH
  
 # Uncomment the following line if you don't like systemctl's auto-paging feature: # Uncomment the following line if you don't like systemctl's auto-paging feature:
Ligne 1907: Ligne 1950:
  
 ----- -----
-<html> +Copyright © 2023 Hugh Norris.
-<div align="center"> +
-Copyright © 2004-2019 Hugh Norris.<br><br> +
-</div> +
-</html>+
Menu