{"id":2641,"date":"2025-07-20T17:23:36","date_gmt":"2025-07-20T16:23:36","guid":{"rendered":"https:\/\/workboot.fr\/ciela\/?page_id=2641"},"modified":"2025-07-20T17:38:06","modified_gmt":"2025-07-20T16:38:06","slug":"les-variables-en-shell-bash","status":"publish","type":"page","link":"https:\/\/workboot.fr\/ciela\/les-variables-en-shell-bash\/","title":{"rendered":"Les variables en shell bash"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">D\u00e9claration d\u2019une variable<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>nom_variable=valeur<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u26a0\ufe0f <strong>Pas d&rsquo;espaces<\/strong> autour du <code>=<\/code> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">nom=\u00a0\u00bbAlice\u00a0\u00bb # \u2705 Correct<br>nom = \u00ab\u00a0Alice\u00a0\u00bb # \u274c Faux (erreur de syntaxe)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Exemples:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>prenom=\"Alice\"\nage=30\nville=\"Paris\"<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Utilisation (appel) d\u2019une variable<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"Bonjour $prenom, tu as $age ans.\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">ou<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"Bonjour ${prenom}, bienvenue \u00e0 ${ville}.\"<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Variables interactives avec <code>read<\/code><\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>read -p \"Quel est ton nom ? \" nom\necho \"Salut $nom !\"<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Op\u00e9rations sur variables num\u00e9riques<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>a=5<br>b=3<br>somme=$((a + b))<br>echo \"La somme est : $somme\"<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Variables d\u2019environnement vs variables locales<\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Type<\/th><th>Visible dans les sous-processus ?<\/th><th>Exemple<\/th><\/tr><\/thead><tbody><tr><td>Locale (par d\u00e9faut)<\/td><td>\u274c Non<\/td><td><code>nom=\"Alice\"<\/code><\/td><\/tr><tr><td>Export\u00e9e (environnement)<\/td><td>\u2705 Oui<\/td><td><code>export nom=\"Alice\"<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Exemple d&rsquo;export:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>etudiant@ordi:~\/Works\/TP0_BASH\/exercice1$ prenom=\"caroline\"\netudiant@ordi:~\/Works\/TP0_BASH\/exercice1$ echo $prenom\ncaroline\netudiant@ordi:~\/Works\/TP0_BASH\/exercice1$ bash\netudiant@ordi:~\/Works\/TP0_BASH\/exercice1$ echo $prenom\n\netudiant@ordi:~\/Works\/TP0_BASH\/exercice1$ exit\nexit\netudiant@ordi:~\/Works\/TP0_BASH\/exercice1$ echo $prenom\ncaroline\netudiant@ordi:~\/Works\/TP0_BASH\/exercice1$ export prenom\netudiant@ordi:~\/Works\/TP0_BASH\/exercice1$ echo $prenom\ncaroline\netudiant@ordi:~\/Works\/TP0_BASH\/exercice1$ bash\netudiant@ordi:~\/Works\/TP0_BASH\/exercice1$ echo $prenom\ncaroline\netudiant@ordi:~\/Works\/TP0_BASH\/exercice1$ <\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Supprimer ou r\u00e9initialiser une variable<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>unset ma_variable<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Synth\u00e8se par l&rsquo;exemple<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nread -p \"Entrez votre pr\u00e9nom : \" prenom\nread -p \"Entrez votre \u00e2ge : \" age\n\necho \"Bonjour $prenom, vous avez $age ans.\"\n\nannee_naissance=$(( $(date +%Y) - age ))\necho \"Vous \u00eates probablement n\u00e9(e) en $annee_naissance.\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>D\u00e9claration d\u2019une variable \u26a0\ufe0f Pas d&rsquo;espaces autour du = nom=\u00a0\u00bbAlice\u00a0\u00bb # \u2705 Correctnom = \u00ab\u00a0Alice\u00a0\u00bb # \u274c Faux (erreur de syntaxe) Exemples: Utilisation (appel) d\u2019une variable ou Variables interactives avec [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-2641","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Les variables en shell bash - workboot<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/workboot.fr\/ciela\/les-variables-en-shell-bash\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Les variables en shell bash - workboot\" \/>\n<meta property=\"og:description\" content=\"D\u00e9claration d\u2019une variable \u26a0\ufe0f Pas d&rsquo;espaces autour du = nom=\u00a0\u00bbAlice\u00a0\u00bb # \u2705 Correctnom = \u00ab\u00a0Alice\u00a0\u00bb # \u274c Faux (erreur de syntaxe) Exemples: Utilisation (appel) d\u2019une variable ou Variables interactives avec [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/workboot.fr\/ciela\/les-variables-en-shell-bash\/\" \/>\n<meta property=\"og:site_name\" content=\"workboot\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-20T16:38:06+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/les-variables-en-shell-bash\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/les-variables-en-shell-bash\\\/\",\"name\":\"Les variables en shell bash - workboot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\"},\"datePublished\":\"2025-07-20T16:23:36+00:00\",\"dateModified\":\"2025-07-20T16:38:06+00:00\",\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/workboot.fr\\\/ciela\\\/les-variables-en-shell-bash\\\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"name\":\"workboot\",\"description\":\"Open Source, Open Minds \",\"publisher\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\",\"name\":\"workboot\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"contentUrl\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"width\":1024,\"height\":950,\"caption\":\"workboot\"},\"image\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Les variables en shell bash - workboot","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/workboot.fr\/ciela\/les-variables-en-shell-bash\/","og_locale":"fr_FR","og_type":"article","og_title":"Les variables en shell bash - workboot","og_description":"D\u00e9claration d\u2019une variable \u26a0\ufe0f Pas d&rsquo;espaces autour du = nom=\u00a0\u00bbAlice\u00a0\u00bb # \u2705 Correctnom = \u00ab\u00a0Alice\u00a0\u00bb # \u274c Faux (erreur de syntaxe) Exemples: Utilisation (appel) d\u2019une variable ou Variables interactives avec [&hellip;]","og_url":"https:\/\/workboot.fr\/ciela\/les-variables-en-shell-bash\/","og_site_name":"workboot","article_modified_time":"2025-07-20T16:38:06+00:00","twitter_misc":{"Dur\u00e9e de lecture estim\u00e9e":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/workboot.fr\/ciela\/les-variables-en-shell-bash\/","url":"https:\/\/workboot.fr\/ciela\/les-variables-en-shell-bash\/","name":"Les variables en shell bash - workboot","isPartOf":{"@id":"https:\/\/workboot.fr\/ciela\/#website"},"datePublished":"2025-07-20T16:23:36+00:00","dateModified":"2025-07-20T16:38:06+00:00","inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/workboot.fr\/ciela\/les-variables-en-shell-bash\/"]}]},{"@type":"WebSite","@id":"https:\/\/workboot.fr\/ciela\/#website","url":"https:\/\/workboot.fr\/ciela\/","name":"workboot","description":"Open Source, Open Minds ","publisher":{"@id":"https:\/\/workboot.fr\/ciela\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/workboot.fr\/ciela\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/workboot.fr\/ciela\/#organization","name":"workboot","url":"https:\/\/workboot.fr\/ciela\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/","url":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","contentUrl":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","width":1024,"height":950,"caption":"workboot"},"image":{"@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/"}}]}},"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":"D\u00e9claration d\u2019une variable \u26a0\ufe0f Pas d&rsquo;espaces autour du = nom=\u00a0\u00bbAlice\u00a0\u00bb # \u2705 Correctnom = \u00ab\u00a0Alice\u00a0\u00bb # \u274c Faux (erreur de syntaxe) Exemples: Utilisation (appel) d\u2019une variable ou Variables interactives avec [&hellip;]","_links":{"self":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2641","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=2641"}],"version-history":[{"count":5,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2641\/revisions"}],"predecessor-version":[{"id":2648,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2641\/revisions\/2648"}],"wp:attachment":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/media?parent=2641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}