{"id":2627,"date":"2025-07-20T16:59:20","date_gmt":"2025-07-20T15:59:20","guid":{"rendered":"https:\/\/workboot.fr\/ciela\/?page_id=2627"},"modified":"2025-11-06T16:50:17","modified_gmt":"2025-11-06T15:50:17","slug":"tp0_bash-shell","status":"publish","type":"page","link":"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/","title":{"rendered":"TP0_SHELL BASH"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><a href=\"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/11\/terminal.jpeg\"><img loading=\"lazy\" decoding=\"async\" width=\"252\" height=\"200\" src=\"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/11\/terminal.jpeg\" alt=\"\" class=\"wp-image-4965\"\/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Pour ce TP on va utiliser <a href=\"https:\/\/workboot.fr\/ciela\/monia\/\">Monia <\/a>, a installer sur vos postes<\/p>\n\n\n\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-8f761849 wp-block-group-is-layout-flex\">\n<ul class=\"wp-block-list\">\n<li>Le Bash shell permet d\u2019interagir directement avec le syst\u00e8me Linux, en ex\u00e9cutant rapidement des commandes pour g\u00e9rer fichiers, dossiers et processus.<\/li>\n\n\n\n<li>Il offre une grande efficacit\u00e9 : une seule ligne de commande peut remplacer plusieurs actions que l\u2019on ferait manuellement via une interface graphique.<\/li>\n\n\n\n<li>Gr\u00e2ce aux scripts Bash, on peut automatiser des t\u00e2ches r\u00e9p\u00e9titives (sauvegardes, d\u00e9ploiements, surveillance syst\u00e8me), ce qui fait gagner du temps et r\u00e9duit les erreurs humaines.<\/li>\n\n\n\n<li>C\u2019est un outil puissant et flexible qui donne un contr\u00f4le total sur le syst\u00e8me, indispensable pour l\u2019administration, le d\u00e9veloppement et le d\u00e9pannage.<\/li>\n\n\n\n<li>Apprendre Bash est aussi une comp\u00e9tence universelle, car il est pr\u00e9sent sur la plupart des syst\u00e8mes Unix\/Linux et m\u00eame disponible sous Windows.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/16.0.1\/svg\/1f552.svg\" alt=\"\ud83d\udd52\" style=\"width:32px;height:auto\"\/><figcaption class=\"wp-element-caption\">6 h maximum<\/figcaption><\/figure>\n\n\n\n<nav aria-label=\"Table des mati\u00e8res\" class=\"wp-block-table-of-contents\"><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#prerequis\">Pr\u00e9requis:<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#but\">But:<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#repertoire-du-travail\">R\u00e9pertoire du travail:<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#presentation-de-tp0-shell-bash\">Pr\u00e9sentation de TP0_SHELL BASH<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#nous-allons-faire-du-shell-scripting\">nous allons faire du \u00ab\u00a0shell scripting\u00a0\u00bb<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#bonjour-le-monde\">Bonjour le monde <\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#a-quoi-sert-la-premiere-ligne\">A quoi sert la premi\u00e8re ligne <\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#executer-a-l-aide-de-bash-le-code-bonjour-sh\">Ex\u00e9cuter \u00e0 l&rsquo;aide de bash le code bonjour.sh<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#rendre-le-code-bonjour-sh-executable\">Rendre le code bonjour.sh ex\u00e9cutable<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#donner-le-resultat-de-ce-code\">Donner le r\u00e9sultat de ce code<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#avec-monia-donner-l-organigramme-et-le-pseudo-langage-de-bonjour\">Avec Monia donner l&rsquo;organigramme et le Pseudo langage de bonjour<\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#alternative-si-if\">Alternative Si (IF)<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#rendre-le-code-executable\">Rendre le code ex\u00e9cutable<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#avec-la-commande-man-trouver-ce-que-fait-n-pour-echo\">Avec la commande man , trouver ce que fait -n pour echo<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#expliquer-le-test-age-ge-18\">Expliquer le test [ $age -ge 18 ]<\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#ecrire-un-code-script-shell-bash\">Ecrire un code , script shell bash <\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#for-pour-liste\">FOR  (POUR) liste<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#exemple-de-code-for-1-sh\">exemple de code for_1.sh:<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-le-code-for-1-sh-1\">Tester le code for_1.sh<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#avec-monia-donner-l-oganigramme-et-le-pl-de-for-1\">Avec Monia , donner l&rsquo;oganigramme et le PL de FOR 1<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#exemple-de-code-for-1-sh\">exemple de code for_2.sh:<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-le-code-for-2-sh-1\">Tester le code for_2.sh<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-le-code-for-2-sh\">Tester le code for_2.sh<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#avec-monia-donner-l-organigramme-et-le-pl-de-for-2\">Avec Monia , donner l\u2019organigramme et le PL de FOR 2<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#exemple-de-code-for-1-sh\">exemple de code for_3.sh:<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-le-code-for-3-sh-syntaxe-d-intervalle\">Tester le code for_3.sh  syntaxe d&rsquo;intervalle<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#expliquer-l-intervalle\">Expliquer l&rsquo;intervalle:<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#avec-monia-donner-l-oganigramme-et-le-pl-de-for-1\">Avec Monia , donner l&rsquo;oganigramme et le PL de FOR 3<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#exemple-de-code-for-1-sh\">exemple de code for_4.sh:<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-le-code-for-4-sh-syntaxe-d-intervalle-et-pas\">Tester le code for_4.sh  syntaxe d&rsquo;intervalle et  pas<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#expliquer-l-intervalle-et-pas\">Expliquer l&rsquo;intervalle et pas :<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#exemple-de-code-for-1-sh\">exemple de code for_5.sh:<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-le-code-for-5-sh\">Tester le code for_5.sh<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#regarder-et-expliquer-avec-man-seq\">Regarder et expliquer avec man seq<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-for-6-sh-executer-ls-pour-faire-une-liste\">Tester  for_6.sh  (executer ls pour faire une liste)<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-for-7-sh\">Tester for_7.sh<\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tant-que-until\">Tant que (until)<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-ce-code\">Tester ce code<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#donner-l-organigramme-et-le-pl\">Donner l&rsquo;organigramme et le PL<\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#les-cas-case\">Les cas (case)<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-ce-code-1\">Tester ce code<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#donner-l-organigramme-et-le-pl-1\">Donner l&rsquo;organigramme et le PL<\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#fonction-en-shell-bash\">Fonction en Shell BASH<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-ce-code-2\">Tester ce code<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#donner-les-organigrammes-et-les-pl\">Donner les organigrammes et les PL <\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#fonction-addition-passage-de-parametres\">Fonction addition (passage de param\u00e8tres)<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#tester-ce-code-3\">Tester ce code <\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/tp0_bash-shell\/#donner-l-organigramme-et-le-pl-2\">Donner l&rsquo;organigramme et le PL<\/a><\/li><\/ol><\/li><\/ol><\/nav>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"prerequis\">Pr\u00e9requis:<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Les<a href=\"https:\/\/workboot.fr\/ciela\/les-variables-en-shell-bash\/\"> variables en shell bash<\/a><\/li>\n\n\n\n<li>Utilisation de l\u2019interpr\u00e9teur<a href=\"https:\/\/workboot.fr\/ciela\/bash-shell\/\"> bash<\/a> et le cours<a href=\"https:\/\/workboot.fr\/ciela\/bash-shell-2\/\"> script shell<\/a><\/li>\n\n\n\n<li>vi \/ vim<\/li>\n\n\n\n<li><a href=\"https:\/\/workboot.fr\/ciela\/monia\/\">Monia<\/a>&nbsp;base algorithme , organigrammes et Pseudo Langage<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"but\">But:<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>apprendre \u00e0 coder , utiliser la puissance d\u2019une machine, qui ne se lasse pas de r\u00e9p\u00e9ter !<\/li>\n\n\n\n<li>R\u00e9fl\u00e9chir pour cr\u00e9er des codes structur\u00e9s<\/li>\n\n\n\n<li>savoir r\u00e9aliser des petits scripts pour faciliter l&rsquo;administration syst\u00e8me .<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"repertoire-du-travail\">R\u00e9pertoire du travail:<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">~\/Works\/TP0_SHELL BASH<\/p>\n\n\n\n<hr class=\"wp-block-separator aligncenter has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"presentation-de-tp0-shell-bash\">Pr\u00e9sentation de TP0_SHELL BASH<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Rappelons que Bash interpr\u00e8te et ex\u00e9cute les commandes de mani\u00e8re interactive, ligne apr\u00e8s ligne, en temps r\u00e9el.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>etudiant@ordi:~\/Works\/TP0_BASH$ echo \"Bonjour le monde !\"\nBonjour le monde !\netudiant@ordi:~\/Works\/TP0_BASH$ echo \"entrer votre nom :\"\nentrer votre nom :\netudiant@ordi:~\/Works\/TP0_BASH$ read nom\ncaroline\netudiant@ordi:~\/Works\/TP0_BASH$ echo \"Bonjour $nom\"\nBonjour caroline\netudiant@ordi:~\/Works\/TP0_BASH$ <\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"nous-allons-faire-du-shell-scripting\">nous allons faire du \u00ab\u00a0shell scripting\u00a0\u00bb<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Le shell scripting est un langage de scriptage orient\u00e9 syst\u00e8me, utilis\u00e9 pour coder des encha\u00eenements de commandes, automatisant des processus et am\u00e9liorant la productivit\u00e9 du d\u00e9veloppeur.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">le cours  est ici  <a href=\"https:\/\/workboot.fr\/ciela\/bash-shell\/\">shell bash<\/a>  et<a href=\"https:\/\/workboot.fr\/ciela\/bash-shell-2\/\"> Script shell bash<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"bonjour-le-monde\">Bonjour le monde <\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">R\u00e9pertoire:bonjour, Code : bonjour.sh<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A l&rsquo;aide vi r\u00e9aliser le fichier bonjour.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\necho \"Bonjour le monde ! \"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a-quoi-sert-la-premiere-ligne\">A quoi sert la premi\u00e8re ligne <\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"executer-a-l-aide-de-bash-le-code-bonjour-sh\">Ex\u00e9cuter \u00e0 l&rsquo;aide de bash le code bonjour.sh<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"rendre-le-code-bonjour-sh-executable\">Rendre le code bonjour.sh ex\u00e9cutable<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"donner-le-resultat-de-ce-code\">Donner le r\u00e9sultat de ce code<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"avec-monia-donner-l-organigramme-et-le-pseudo-langage-de-bonjour\">Avec Monia donner l&rsquo;organigramme et le Pseudo langage de bonjour<\/h2>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"alternative-si-if\">Alternative Si (IF)<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">r\u00e9pertoire : age , code : age.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash \necho -n \"votre age :\"\nread age\nif &#91; $age -ge 18 ]\nthen \necho \"Vous \u00eates majeur\"\nelse \necho \"vous n'\u00eates pas majeur , demander \u00e0 vos parents !\"\nfi<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"rendre-le-code-executable\">Rendre le code ex\u00e9cutable<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"avec-la-commande-man-trouver-ce-que-fait-n-pour-echo\">Avec la commande man , trouver ce que fait -n pour echo<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"expliquer-le-test-age-ge-18\">Expliquer le test [ $age -ge 18 ]<\/h2>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"ecrire-un-code-script-shell-bash\">Ecrire un code , script shell bash <\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">r\u00e9pertoire :code_0, code : code_0.sh<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> Ecrire un code&nbsp;<strong>code_0.sh<\/strong>&nbsp;qui va \u00e9crire&nbsp; un fichier bonjour.txt&nbsp; contenant bonjour le monde si il n&rsquo;existe pas, sans poser de question , si il existe&nbsp; on ne fait rien<\/p>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>Solution code_0.sh<\/summary>\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# on passe en parametre le nom du fichier\n# .\/code.sh bonjour.txt  # par exemple\nif &#91; $# -ne 1 ] \nthen\necho \"il me faut un argument svp \"\necho \" syntaxe : .\/code0.sh  fichier \"\nexit\nfi\nif &#91; -e $1 ]\nthen \necho \"le fichier $1 existe d\u00e9ja !\"\nelse\necho \"le fichier $1 n'existe pas ! mais je le fait \"\necho \"Bonjour le monde ! \" &gt; $1  # on cr\u00e9e le fichier \nfi<\/code><\/pre>\n<\/details>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"for-pour-liste\">FOR  (POUR) liste<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">R\u00e9pertoire : for , code for_x.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for variable in liste_valeurs\ndo\n    commandes\ndone<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"exemple-de-code-for-1-sh\">exemple de code for_1.sh:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# FOR 1\nfor fruit in pomme banane orange\ndo\n    echo \"J'aime les $fruit\"\ndone<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tester-le-code-for-1-sh-1\">Tester le code for_1.sh<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">relever la liste <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"avec-monia-donner-l-oganigramme-et-le-pl-de-for-1\">Avec Monia , donner l&rsquo;oganigramme et le PL de FOR 1<\/h3>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"exemple-de-code-for-1-sh\">exemple de code for_2.sh:<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tester-le-code-for-2-sh-1\">Tester le code for_2.sh<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# FOR 2\nfor nom in {\"Dorian\",\"Arthur\",\"Paul\",\"Armand\"}\ndo\necho $nom\ndone<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tester-le-code-for-2-sh\">Tester le code for_2.sh<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"avec-monia-donner-l-organigramme-et-le-pl-de-for-2\">Avec Monia , donner l\u2019organigramme et le PL de FOR 2<\/h3>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"exemple-de-code-for-1-sh\">exemple de code for_3.sh:<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tester-le-code-for-3-sh-syntaxe-d-intervalle\">Tester le code for_3.sh  syntaxe d&rsquo;intervalle<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# FOR 3\nfor i in {1..5}        # Syntaxe d'intervalle\ndo\n    echo \"Num\u00e9ro: $i\"\ndone<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"expliquer-l-intervalle\">Expliquer l&rsquo;intervalle:<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"avec-monia-donner-l-oganigramme-et-le-pl-de-for-1\">Avec Monia , donner l&rsquo;oganigramme et le PL de FOR 3<\/h3>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"exemple-de-code-for-1-sh\">exemple de code for_4.sh:<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tester-le-code-for-4-sh-syntaxe-d-intervalle-et-pas\">Tester le code for_4.sh  syntaxe d&rsquo;intervalle et  pas<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# FOR 4\nfor i in {0..10..2}    # De 0 \u00e0 10 par pas de 2\ndo\n    echo \"$i\"\ndone<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"expliquer-l-intervalle-et-pas\">Expliquer l&rsquo;intervalle et pas :<\/h3>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"exemple-de-code-for-1-sh\">exemple de code for_5.sh:<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tester-le-code-for-5-sh\">Tester le code for_5.sh<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# FOR 5\nfor i in `seq 1 10`;\ndo\n        echo $i\ndone;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"regarder-et-expliquer-avec-man-seq\">Regarder et expliquer avec man seq<\/h3>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tester-for-6-sh-executer-ls-pour-faire-une-liste\">Tester  for_6.sh  (executer ls pour faire une liste)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# FOR 6\nfor fichier in `ls`\ndo\n        echo \"Fichier trouv\u00e9 : $fichier\"\ndone<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tester-for-7-sh\">Tester for_7.sh<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# FOR 7\nfor (( count=10; count&gt;0; count-- ))\ndo\necho -n \"$count \"\ndone<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">comme en C! <\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"tant-que-until\">Tant que (until)<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">r\u00e9pertoire: moyenne , code : moyenne.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash \n# Tant que (until)\nnote=0\nmoyenne=0\ni=0\n\nuntil &#91; \"$note\" -lt 0 ]; \ndo\n    echo \"Entrez votre note (q pour quitter) :\" \n    read -r note\n    if &#91; \"$note\" = \"q\" ]; then\n        note=-1\n        echo \"au revoir !\" \n    elif &#91; \"$note\" -ge 16 ]; then\n        echo \"tr\u00e8s bien\" \n    elif &#91; \"$note\" -ge 14 ]; then\n        echo \"bien\" \n    elif &#91; \"$note\" -ge 12 ]; then\n        echo \"assez bien\" \n    elif &#91; \"$note\" -ge 10 ]; then\n        echo \"moyen\" \n    elif &#91; \"$note\" -ge 0 ]; then\n        echo \"insuffisant\" \n    else\n        echo \"au revoir !\" \n    fi\n\n    if &#91; \"$note\" -ge 0 ]; then\n        let moyenne=$moyenne+$note\n        let i=$i+1\n    fi\ndone\n\nif &#91; \"$i\" -le 0 ]; then\n    let i=1\nfi\n\nlet moyenne=$moyenne\/$i\necho \"La moyenne est de $moyenne ($i notes)\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tester-ce-code\">Tester ce code<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"donner-l-organigramme-et-le-pl\">Donner l&rsquo;organigramme et le PL<\/h2>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"les-cas-case\">Les cas (case)<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">r\u00e9pertoire: lescas , code : lescas.sh<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lescas.sh:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# programme exemple lescas.sh\ncase $# in\n  0) echo \"aucun parametre\"\n     echo \"Syntaxe :  $0 &lt;nom d'utilisateur&gt;\";;\n  1) echo \"1 parametre passe au programme : $1\";;\n  2) echo \"2 parametres passes au programme : $1 et $2\";;\n  *) echo \"TROP DE PARAMETRES !\"\nesac<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tester-ce-code-1\">Tester ce code<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"donner-l-organigramme-et-le-pl-1\">Donner l&rsquo;organigramme et le PL<\/h2>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"fonction-en-shell-bash\">Fonction en Shell BASH<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">r\u00e9pertoire: fonction , code : fonction.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# ma fonction !\nfunction afficher\n{\necho \"Bonjour le monde\"\n}\n\n#programme principal\nafficher  # afficher 3 fois!\nafficher\nafficher<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tester-ce-code-2\">Tester ce code<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"donner-les-organigrammes-et-les-pl\">Donner les organigrammes et les PL <\/h2>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"fonction-addition-passage-de-parametres\">Fonction addition (passage de param\u00e8tres)<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">r\u00e9pertoire: addition, code:addition.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# fonction addition avec passage \n\nfunction addition\n{\nlocal a=$1\nlocal b=$2\nlocal somme=$((a+b))\nreturn $somme\n}\n\n# programme principal\n\naddition 5 15\necho $?  #affiche la somme (envoy\u00e9 par le return)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tester-ce-code-3\">Tester ce code <\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"donner-l-organigramme-et-le-pl-2\">Donner l&rsquo;organigramme et le PL<\/h2>\n","protected":false},"excerpt":{"rendered":"<p>Pour ce TP on va utiliser Monia , a installer sur vos postes Pr\u00e9requis: But: R\u00e9pertoire du travail: ~\/Works\/TP0_SHELL BASH Pr\u00e9sentation de TP0_SHELL BASH Rappelons que Bash interpr\u00e8te et ex\u00e9cute les commandes de mani\u00e8re interactive, ligne apr\u00e8s ligne, en temps r\u00e9el. nous allons faire du \u00ab\u00a0shell scripting\u00a0\u00bb Le shell scripting est un langage de scriptage [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-2627","page","type-page","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"https:\/\/workboot.fr\/ciela\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Pour ce TP on va utiliser Monia , a installer sur vos postes Pr\u00e9requis: But: R\u00e9pertoire du travail: ~\/Works\/TP0_SHELL BASH Pr\u00e9sentation de TP0_SHELL BASH Rappelons que Bash interpr\u00e8te et ex\u00e9cute les commandes de mani\u00e8re interactive, ligne apr\u00e8s ligne, en temps r\u00e9el. nous allons faire du \u00ab\u00a0shell scripting\u00a0\u00bb Le shell scripting est un langage de scriptage\u2026","_links":{"self":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/comments?post=2627"}],"version-history":[{"count":64,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2627\/revisions"}],"predecessor-version":[{"id":4966,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2627\/revisions\/4966"}],"wp:attachment":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/media?parent=2627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}