{"id":2605,"date":"2025-07-18T14:27:00","date_gmt":"2025-07-18T13:27:00","guid":{"rendered":"https:\/\/workboot.fr\/ciela\/?page_id=2605"},"modified":"2026-02-16T15:39:44","modified_gmt":"2026-02-16T14:39:44","slug":"bash-shell-passage-darguments","status":"publish","type":"page","link":"https:\/\/workboot.fr\/ciela\/bash-shell-passage-darguments\/","title":{"rendered":"BASH SHELL, Passage d&rsquo;arguments"},"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\/bash-shell-passage-darguments\/#fichier-test-sh\">fichier test.sh:<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/bash-shell-passage-darguments\/#ce-qu-il-faut-retenir-sur-les-arguments-en-shell\">Ce qu&rsquo;il faut retenir sur les arguments en shell<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/bash-shell-passage-darguments\/#lister-tous-les-arguments-avec\">Lister tous les arguments avec $@<\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/workboot.fr\/ciela\/bash-shell-passage-darguments\/#les-fonctions-en-shell\">Les fonctions en Shell<\/a><\/li><\/ol><\/nav>\n\n\n\n<p class=\"wp-block-paragraph\">En shell comme dans tous les langages on peut passer des arguments<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -l  # -l est l'argument pass\u00e9 \u00e0 ls <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Exemple avec le script test suivant:<\/p>\n\n\n\n<h2 id=\"fichier-test-sh\" class=\"wp-block-heading\">fichier test.sh:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\necho \"Bonjour le monde !\"\necho \"\\$#:\" $#\necho \"\\$1:\" $1\necho \"\\$2:\" $2<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod +x file.sh  # pour rendre ex\u00e9cutable file<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>bruno@bruno-HP-250-G6-Notebook-PC:~\/test$ bash test.sh \nBonjour le monde !\n$#: 0\n$1:\n$2:\nbruno@bruno-HP-250-G6-Notebook-PC:~\/test$ bash test.sh 5 6 9\nBonjour le monde !\n$#: 3\n$1: 5\n$2: 6\nbruno@bruno-HP-250-G6-Notebook-PC:~\/test$<\/code><\/pre>\n\n\n\n<h2 id=\"ce-qu-il-faut-retenir-sur-les-arguments-en-shell\" class=\"wp-block-heading\">Ce qu&rsquo;il faut retenir sur les arguments en shell<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Variable<\/th><th>Signification<\/th><th>Exemple si on ex\u00e9cute <code>.\/script.sh A B C<\/code><\/th><\/tr><\/thead><tbody><tr><td><code>$0<\/code><\/td><td>Nom du script tel qu&rsquo;invoqu\u00e9<\/td><td><code>.\/script.sh<\/code><\/td><\/tr><tr><td><code>$1<\/code>, <code>$2<\/code>&#8230;<\/td><td>Arguments positionnels (1er, 2e, etc.)<\/td><td><code>$1 = A<\/code>, <code>$2 = B<\/code>, <code>$3 = C<\/code><\/td><\/tr><tr><td><code>$#<\/code><\/td><td>Nombre total d\u2019arguments pass\u00e9s<\/td><td><code>3<\/code><\/td><\/tr><tr><td><code>$*<\/code><\/td><td>Tous les arguments sous forme <strong>d\u2019une seule cha\u00eene<\/strong><\/td><td><code>\"A B C\"<\/code><\/td><\/tr><tr><td><code>$@<\/code><\/td><td>Tous les arguments sous forme <strong>s\u00e9par\u00e9e<\/strong><\/td><td><code>\"A\" \"B\" \"C\"<\/code><\/td><\/tr><tr><td><code>\"$*\"<\/code><\/td><td>Tous les arguments dans <strong>une cha\u00eene unique<\/strong> (entre guillemets)<\/td><td><code>\"A B C\"<\/code> (1 seule boucle)<\/td><\/tr><tr><td><code>\"$@\"<\/code><\/td><td>Tous les arguments, <strong>chacun s\u00e9par\u00e9<\/strong>, entre guillemets<\/td><td><code>\"A\"<\/code> <code>\"B\"<\/code> <code>\"C\"<\/code> (3 it\u00e9rations en boucle)<\/td><\/tr><tr><td><code>$$<\/code><\/td><td>PID (identifiant du processus) du script<\/td><td>ex. <code>12345<\/code><\/td><\/tr><tr><td><code>$?<\/code><\/td><td>Code de retour de la <strong>derni\u00e8re commande ex\u00e9cut\u00e9e<\/strong><\/td><td><code>0<\/code> ou autre selon succ\u00e8s\/\u00e9chec<\/td><\/tr><tr><td><code>$!<\/code><\/td><td>PID du <strong>dernier processus ex\u00e9cut\u00e9 en arri\u00e8re-plan<\/strong><\/td><td>PID d\u2019un <code>command &amp;<\/code><\/td><\/tr><tr><td><code>$-<\/code><\/td><td>Options actuelles du shell (<code>set<\/code>)<\/td><td>ex. <code>himBH<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 id=\"lister-tous-les-arguments-avec\" class=\"wp-block-heading\">Lister tous les arguments avec $@<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\nfor arg in \"$@\"; do\n  echo \"Argument : $arg\"\ndone<\/code><\/pre>\n\n\n\n<h2 id=\"les-fonctions-en-shell\" class=\"wp-block-heading\">Les fonctions en Shell<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>bonjour() { echo \"Bonjour le monde\"; }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">exemple d&rsquo;utilisation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bruno@elliott:~$ bonjour() { echo \"Bonjour le monde\"; }\nbruno@elliott:~$ bonjour\nBonjour le monde\nbruno@elliott:~$ \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>En shell comme dans tous les langages on peut passer des arguments Exemple avec le script test suivant: fichier test.sh: Ce qu&rsquo;il faut retenir sur les arguments en shell Variable [&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-2605","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>BASH SHELL, Passage d&#039;arguments - 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\/bash-shell-passage-darguments\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"BASH SHELL, Passage d&#039;arguments - workboot\" \/>\n<meta property=\"og:description\" content=\"En shell comme dans tous les langages on peut passer des arguments Exemple avec le script test suivant: fichier test.sh: Ce qu&rsquo;il faut retenir sur les arguments en shell Variable [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/workboot.fr\/ciela\/bash-shell-passage-darguments\/\" \/>\n<meta property=\"og:site_name\" content=\"workboot\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-16T14:39:44+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\\\/bash-shell-passage-darguments\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/bash-shell-passage-darguments\\\/\",\"name\":\"BASH SHELL, Passage d'arguments - workboot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\"},\"datePublished\":\"2025-07-18T13:27:00+00:00\",\"dateModified\":\"2026-02-16T14:39:44+00:00\",\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/workboot.fr\\\/ciela\\\/bash-shell-passage-darguments\\\/\"]}]},{\"@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":"BASH SHELL, Passage d'arguments - 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\/bash-shell-passage-darguments\/","og_locale":"fr_FR","og_type":"article","og_title":"BASH SHELL, Passage d'arguments - workboot","og_description":"En shell comme dans tous les langages on peut passer des arguments Exemple avec le script test suivant: fichier test.sh: Ce qu&rsquo;il faut retenir sur les arguments en shell Variable [&hellip;]","og_url":"https:\/\/workboot.fr\/ciela\/bash-shell-passage-darguments\/","og_site_name":"workboot","article_modified_time":"2026-02-16T14:39:44+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\/bash-shell-passage-darguments\/","url":"https:\/\/workboot.fr\/ciela\/bash-shell-passage-darguments\/","name":"BASH SHELL, Passage d'arguments - workboot","isPartOf":{"@id":"https:\/\/workboot.fr\/ciela\/#website"},"datePublished":"2025-07-18T13:27:00+00:00","dateModified":"2026-02-16T14:39:44+00:00","inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/workboot.fr\/ciela\/bash-shell-passage-darguments\/"]}]},{"@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":"En shell comme dans tous les langages on peut passer des arguments Exemple avec le script test suivant: fichier test.sh: Ce qu&rsquo;il faut retenir sur les arguments en shell Variable [&hellip;]","_links":{"self":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2605","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=2605"}],"version-history":[{"count":4,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2605\/revisions"}],"predecessor-version":[{"id":6803,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/2605\/revisions\/6803"}],"wp:attachment":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/media?parent=2605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}