{"id":2621,"date":"2025-07-20T16:17:26","date_gmt":"2025-07-20T15:17:26","guid":{"rendered":"https:\/\/workboot.fr\/ciela\/?page_id=2621"},"modified":"2025-07-20T16:25:58","modified_gmt":"2025-07-20T15:25:58","slug":"les-tests-en-bash-shell","status":"publish","type":"page","link":"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/","title":{"rendered":"les tests en bash shell"},"content":{"rendered":"\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\/les-tests-en-bash-shell\/#types-de-tests\">Types de tests<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/#tests-de-fichiers\">Tests de fichiers<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/#tests-de-chaines-de-caracteres\">Tests de cha\u00eenes de caract\u00e8res<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/#tests-numeriques\">Tests num\u00e9riques<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/#combinaisons-logiques\">Combinaisons logiques<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/#et-logique\">ET logique : &amp;&amp;<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/#ou-logique\">OU logique : ||<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/#negation\">N\u00e9gation : !<\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/#exemple-complet\">\ud83d\udd38 Exemple complet<\/a><\/li><\/ol><\/li><\/ol><\/nav>\n\n\n\n<p class=\"wp-block-paragraph\">Les <strong>tests en Bash shell<\/strong> permettent de faire des v\u00e9rifications logiques ou arithm\u00e9tiques (fichiers, cha\u00eenes, entiers, etc.). Voici un r\u00e9sum\u00e9 des diff\u00e9rents types de tests que tu peux effectuer avec la commande <code>test<\/code>, ou sa forme \u00e9quivalente entre crochets <code>[ ... ]<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if &#91; CONDITION ]; then\n    # commandes si vrai\nelse\n    # commandes si faux\nfi<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Important : toujours <strong>laisser des espaces autour des crochets <code>[<\/code> et <code>]<\/code><\/strong>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"types-de-tests\">Types de tests<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tests-de-fichiers\"><strong>Tests de fichiers<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Test<\/th><th>Signification<\/th><\/tr><\/thead><tbody><tr><td><code>[ -e fichier ]<\/code><\/td><td>Le fichier existe (quelque soit son type)<\/td><\/tr><tr><td><code>[ -f fichier ]<\/code><\/td><td>Le fichier est un fichier ordinaire<\/td><\/tr><tr><td><code>[ -d dossier ]<\/code><\/td><td>C\u2019est un dossier<\/td><\/tr><tr><td><code>[ -r fichier ]<\/code><\/td><td>Le fichier est lisible<\/td><\/tr><tr><td><code>[ -w fichier ]<\/code><\/td><td>Le fichier est modifiable<\/td><\/tr><tr><td><code>[ -x fichier ]<\/code><\/td><td>Le fichier est ex\u00e9cutable<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tests-de-chaines-de-caracteres\">Tests de cha\u00eenes de caract\u00e8res<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Test<\/th><th>Signification<\/th><\/tr><\/thead><tbody><tr><td><code>[ \"$str1\" = \"$str2\" ]<\/code><\/td><td>Les cha\u00eenes sont \u00e9gales<\/td><\/tr><tr><td><code>[ \"$str1\" != \"$str2\" ]<\/code><\/td><td>Les cha\u00eenes sont diff\u00e9rentes<\/td><\/tr><tr><td><code>[ -z \"$str\" ]<\/code><\/td><td>La cha\u00eene est vide<\/td><\/tr><tr><td><code>[ -n \"$str\" ]<\/code><\/td><td>La cha\u00eene n\u2019est pas vide<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tests-numeriques\">Tests num\u00e9riques<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Test<\/th><th>Signification<\/th><\/tr><\/thead><tbody><tr><td><code>[ \"$a\" -eq \"$b\" ]<\/code><\/td><td><code>$a<\/code> est \u00e9gal \u00e0 <code>$b<\/code><\/td><\/tr><tr><td><code>[ \"$a\" -ne \"$b\" ]<\/code><\/td><td><code>$a<\/code> est diff\u00e9rent de <code>$b<\/code><\/td><\/tr><tr><td><code>[ \"$a\" -lt \"$b\" ]<\/code><\/td><td><code>$a<\/code> est inf\u00e9rieur \u00e0 <code>$b<\/code><\/td><\/tr><tr><td><code>[ \"$a\" -le \"$b\" ]<\/code><\/td><td><code>$a<\/code> est inf\u00e9rieur ou \u00e9gal \u00e0 <code>$b<\/code><\/td><\/tr><tr><td><code>[ \"$a\" -gt \"$b\" ]<\/code><\/td><td><code>$a<\/code> est sup\u00e9rieur \u00e0 <code>$b<\/code><\/td><\/tr><tr><td><code>[ \"$a\" -ge \"$b\" ]<\/code><\/td><td><code>$a<\/code> est sup\u00e9rieur ou \u00e9gal \u00e0 <code>$b<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"combinaisons-logiques\">Combinaisons logiques<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"et-logique\"><strong>ET logique<\/strong> : <code>&amp;&amp;<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">if [ $a -gt 0 ] &amp;&amp; [ $a -lt 10 ]; then<br>    echo \"Entre 1 et 9\"<br>fi<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ou-logique\"><strong>OU logique<\/strong> : <code>||<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">if [ $a -lt 0 ] || [ $a -gt 100 ]; then<br>    echo \"Hors de l'intervalle\"<br>fi<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"negation\"><strong>N\u00e9gation<\/strong> : <code>!<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">if [ ! -f fichier.txt ]; then<br>    echo \"Fichier absent\"<br>fi<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"exemple-complet\">\ud83d\udd38 Exemple complet<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br><br>fichier=\"mon_script.sh\"<br><br>if [ -e \"$fichier\" ]; then<br>    echo \"Le fichier existe.\"<br>    <br>    if [ -x \"$fichier\" ]; then<br>        echo \"Le fichier est ex\u00e9cutable.\"<br>    else<br>        echo \"Le fichier n'est pas ex\u00e9cutable.\"<br>    fi<br>else<br>    echo \"Le fichier n'existe pas.\"<br>fi<code><br><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Les tests en Bash shell permettent de faire des v\u00e9rifications logiques ou arithm\u00e9tiques (fichiers, cha\u00eenes, entiers, etc.). Voici un r\u00e9sum\u00e9 des diff\u00e9rents types de tests que tu peux effectuer 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-2621","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 tests en bash shell - 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-tests-en-bash-shell\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"les tests en bash shell - workboot\" \/>\n<meta property=\"og:description\" content=\"Les tests en Bash shell permettent de faire des v\u00e9rifications logiques ou arithm\u00e9tiques (fichiers, cha\u00eenes, entiers, etc.). Voici un r\u00e9sum\u00e9 des diff\u00e9rents types de tests que tu peux effectuer avec [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/\" \/>\n<meta property=\"og:site_name\" content=\"workboot\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-20T15:25:58+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-tests-en-bash-shell\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/les-tests-en-bash-shell\\\/\",\"name\":\"les tests en bash shell - workboot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\"},\"datePublished\":\"2025-07-20T15:17:26+00:00\",\"dateModified\":\"2025-07-20T15:25:58+00:00\",\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/workboot.fr\\\/ciela\\\/les-tests-en-bash-shell\\\/\"]}]},{\"@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 tests en bash shell - 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-tests-en-bash-shell\/","og_locale":"fr_FR","og_type":"article","og_title":"les tests en bash shell - workboot","og_description":"Les tests en Bash shell permettent de faire des v\u00e9rifications logiques ou arithm\u00e9tiques (fichiers, cha\u00eenes, entiers, etc.). Voici un r\u00e9sum\u00e9 des diff\u00e9rents types de tests que tu peux effectuer avec [&hellip;]","og_url":"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/","og_site_name":"workboot","article_modified_time":"2025-07-20T15:25:58+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-tests-en-bash-shell\/","url":"https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/","name":"les tests en bash shell - workboot","isPartOf":{"@id":"https:\/\/workboot.fr\/ciela\/#website"},"datePublished":"2025-07-20T15:17:26+00:00","dateModified":"2025-07-20T15:25:58+00:00","inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/workboot.fr\/ciela\/les-tests-en-bash-shell\/"]}]},{"@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":"Les tests en Bash shell permettent de faire des v\u00e9rifications logiques ou arithm\u00e9tiques (fichiers, cha\u00eenes, entiers, etc.). Voici un r\u00e9sum\u00e9 des diff\u00e9rents types de tests que tu peux effectuer avec [&hellip;]","_links":{"self":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2621","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=2621"}],"version-history":[{"count":3,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2621\/revisions"}],"predecessor-version":[{"id":2626,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2621\/revisions\/2626"}],"wp:attachment":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/media?parent=2621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}