{"id":586812,"date":"2023-08-12T18:00:00","date_gmt":"2023-08-12T15:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-work-with-variables-in-bash\/"},"modified":"2023-08-12T18:00:00","modified_gmt":"2023-08-12T15:00:00","slug":"how-to-work-with-variables-in-bash","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-variables-in-bash\/","title":{"rendered":"#How to Work with Variables in Bash"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a3e55a8afb20\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a3e55a8afb20\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-variables-in-bash\/#Variables_101\" >Variables 101<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-variables-in-bash\/#Examples_of_Bash_Variables\" >Examples of Bash Variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-variables-in-bash\/#How_to_Use_Bash_Variables_in_Scripts\" >How to Use Bash Variables in Scripts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-variables-in-bash\/#How_to_Use_Command_Line_Parameters_in_Scripts\" >How to Use Command Line Parameters in Scripts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-variables-in-bash\/#Working_with_Special_Variables\" >Working with Special Variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-variables-in-bash\/#Environment_Variables\" >Environment Variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-variables-in-bash\/#How_to_Export_Variables\" >How to Export Variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-variables-in-bash\/#How_to_Quote_Variables\" >How to Quote Variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-work-with-variables-in-bash\/#echo_Is_Your_Friend\" >echo Is Your Friend<\/a><\/li><\/ul><\/nav><\/div>\n<div>\n<p>Variables are vital if you want to write <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">script<\/a>s and understand what that code you&#8217;re about to cut and paste from the web will do to your Linux computer. We&#8217;ll get you started!<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":0,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":0,\"nbrPlacementsScanned\":0,\"ruleCount\":10,\"degradationStartingPoint\":2,\"actualCount\":185} --><br \/>\n<!-- Zone: below first paragraph. --><\/p>\n<p><!-- No winning ad found for zone: native in content! --><\/p>\n<h2 id=\"variables-101\"><span class=\"ez-toc-section\" id=\"Variables_101\"><\/span> Variables 101 <span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Variables are named symbols that represent either a string or numeric value. When you use them in commands and expressions, they are treated as if you had typed the value they hold instead of the name of the variable.<br \/>\n<!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":0,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":0,\"nbrPlacementsScanned\":1,\"ruleCount\":10,\"degradationStartingPoint\":2,\"actualCount\":217} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":1,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":1,\"nbrPlacementsScanned\":1,\"ruleCount\":10,\"degradationStartingPoint\":2,\"actualCount\":0} --><br \/>\nTo create a variable, you just provide a name and value for it. Your variable names should be descriptive and remind you of the value they hold. A variable name cannot start with a number, nor can it contain spaces. It can, however, start with an underscore. Apart from that, you can use any mix of upper- and lowercase alphanumeric characters.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":1,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":1,\"nbrPlacementsScanned\":2,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":344} --><\/p>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":1,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":1,\"nbrPlacementsScanned\":2,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":344} --><\/p>\n<h2 id=\"examples-of-bash-variables\"><span class=\"ez-toc-section\" id=\"Examples_of_Bash_Variables\"><\/span> Examples of Bash Variables <span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Here, we&#8217;ll create five variables. The format is to type the name, the equals sign <code>=<\/code>, and the value. Note there isn&#8217;t a space before or after the equals sign. Giving a variable a value is often referred to as assigning a value to the variable.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":1,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":1,\"nbrPlacementsScanned\":2,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":595} --><br \/>\nWe&#8217;ll create four string variables and one numeric variable,<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":1,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":1,\"nbrPlacementsScanned\":2,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":659} --><\/p>\n<pre>my_name=Dave<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":1,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":1,\"nbrPlacementsScanned\":2,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":671} --><\/p>\n<pre>my_boost=Linux<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":1,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":1,\"nbrPlacementsScanned\":2,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":685} --><\/p>\n<pre>him=Popeye<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":1,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":1,\"nbrPlacementsScanned\":2,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":695} --><\/p>\n<pre>his_boost=Spinach<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":1,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":1,\"nbrPlacementsScanned\":2,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":712} --><\/p>\n<pre>this_year=2019<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":1,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":1,\"nbrPlacementsScanned\":2,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":726} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:52.533333333333%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2023\/08\/my-name-replacement.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2023\/08\/my-name-replacement.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2023\/08\/my-name-replacement.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2023\/08\/my-name-replacement.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2023\/08\/my-name-replacement.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"750\" class=\"lazyload\" height=\"394\" alt=\"Defining variables in Linux. \" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2023\/08\/my-name-replacement.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":1,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":1,\"nbrPlacementsScanned\":2,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":966} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":2,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":2,\"nbrPlacementsScanned\":2,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><br \/>\n To <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/man7.org\/linux\/man-pages\/man1\/echo.1.html\">see the value<\/a> held in a variable, use the <code>echo<\/code> command. You must precede the variable name with a dollar sign <code>$<\/code> whenever you reference the value it contains, as shown below:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":2,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":2,\"nbrPlacementsScanned\":3,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":177} --><\/p>\n<pre>echo $my_name<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":2,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":2,\"nbrPlacementsScanned\":3,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":190} --><\/p>\n<pre>echo $my_boost<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":2,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":2,\"nbrPlacementsScanned\":3,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":204} --><\/p>\n<pre>echo $this_year<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":2,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":2,\"nbrPlacementsScanned\":3,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":219} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:25.851393188854%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/2-12.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/2-12.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/2-12.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/2-12.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/2-12.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"167\" alt=\"Using echo to display the values held in variables in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/2-12.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":2,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":2,\"nbrPlacementsScanned\":3,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":459} --><br \/>\nLet&#8217;s use all of our variables at once:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":2,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":2,\"nbrPlacementsScanned\":3,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":502} --><\/p>\n<pre>echo \"$my_boost is to $me as $his_boost is to $him (c) $this_year\"<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":2,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":2,\"nbrPlacementsScanned\":3,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":578} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:18.885448916409%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/3-14.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/3-14.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/3-14.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/3-14.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/3-14.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"122\" alt=\"echo \" is=\"\" to=\"\" as=\"\" in=\"\" a=\"\" terminal=\"\" window=\"\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/3-14.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":2,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":2,\"nbrPlacementsScanned\":3,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":818} --><br \/>\nThe values of the variables replace their names. You can also change the values of variables. To assign a new value to the variable, <code>my_boost<\/code>, you just repeat what you did when you assigned its first value, like so:<br \/>\n<!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":2,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":2,\"nbrPlacementsScanned\":3,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":1033} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":3,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":3,\"nbrPlacementsScanned\":3,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><\/p>\n<pre>my_boost=Tequila<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":3,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":3,\"nbrPlacementsScanned\":4,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":16} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:8.8235294117647%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/5-8.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/5-8.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/5-8.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/5-8.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/5-8.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"57\" alt=\"my_boost=Tequila in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/5-8.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":3,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":3,\"nbrPlacementsScanned\":4,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":256} --><br \/>\nIf you re-run the previous command, you now get a different result:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":3,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":3,\"nbrPlacementsScanned\":4,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":323} --><\/p>\n<pre>echo \"$my_boost is to $me as $his_boost is to $him (c) $this_year\"<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":3,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":3,\"nbrPlacementsScanned\":4,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":399} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:18.885448916409%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/6-7.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/6-7.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/6-7.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/6-7.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/6-7.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"122\" alt=\"echo \" is=\"\" to=\"\" as=\"\" in=\"\" a=\"\" terminalwindow=\"\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/6-7.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":3,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":3,\"nbrPlacementsScanned\":4,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":639} --><br \/>\nSo, you can use the same command that references the same variables and get different results if you change the values held in the variables.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":3,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":3,\"nbrPlacementsScanned\":4,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":780} --><br \/>\nWe&#8217;ll talk about quoting variables later. For now, here are some things to remember:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":3,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":3,\"nbrPlacementsScanned\":4,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":868} --><\/p>\n<ul>\n<li> A variable in single quotes <code>'<\/code> is treated as a literal string, and not as a variable. <\/li>\n<li> Variables in quotation marks <code>\"<\/code> are treated as variables. <\/li>\n<li> To get the value held in a variable, you have to provide the dollar sign <code>$<\/code>. <\/li>\n<li> A variable without the dollar sign <code>$<\/code> only provides the name of the variable. <\/li>\n<\/ul>\n<p><!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":3,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":3,\"nbrPlacementsScanned\":4,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":1181} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":4,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":4,\"nbrPlacementsScanned\":4,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:32.8173374613%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/7-8.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/7-8.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/7-8.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/7-8.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/7-8.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"212\" alt=\"Correct an incorrect examples of referencing variables in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/7-8.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":4,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":4,\"nbrPlacementsScanned\":5,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":240} --><br \/>\nYou can also create a variable that takes its value from an existing variable or number of variables. The following command defines a new variable called <code>drink_of_the_Year,<\/code> and assigns it the combined values of the <code>my_boost<\/code> and <code>this_year<\/code> variables:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":4,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":4,\"nbrPlacementsScanned\":5,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":488} --><\/p>\n<pre>drink_of-the_Year=\"$my_boost $this_year\"<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":4,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":4,\"nbrPlacementsScanned\":5,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":538} --><\/p>\n<pre>echo drink_of_the-Year<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":4,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":4,\"nbrPlacementsScanned\":5,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":560} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:20.433436532508%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/8-9.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/8-9.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/8-9.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/8-9.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/8-9.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"132\" alt=\"drink_of-the_Year=\" in=\"\" a=\"\" terminal=\"\" window=\"\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/8-9.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":4,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":4,\"nbrPlacementsScanned\":5,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":800} --><\/p>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":4,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":4,\"nbrPlacementsScanned\":5,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":800} --><\/p>\n<h2 id=\"how-to-use-bash-variables-in-scripts\"><span class=\"ez-toc-section\" id=\"How_to_Use_Bash_Variables_in_Scripts\"><\/span> How to Use Bash Variables in Scripts <span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Scripts would be completely hamstrung without variables. Variables provide the flexibility that makes a script a <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>, rather than a specific, solution. To illustrate the difference, here&#8217;s a script that counts the files in the <code>\/dev<\/code> directory.<br \/>\n<!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":4,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":4,\"nbrPlacementsScanned\":5,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":1050} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":5,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":5,\"nbrPlacementsScanned\":5,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><br \/>\nType this into a text file, and then save it as <code>fcnt.sh<\/code> (for &#8220;file count&#8221;):<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":5,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":5,\"nbrPlacementsScanned\":6,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":85} --><\/p>\n<pre>#!\/bin\/bashfolder_to_count=\/devfile_count=$(ls $folder_to_count | wc -l)echo $file_count files in $folder_to_count<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":5,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":5,\"nbrPlacementsScanned\":6,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":199} --><br \/>\nBefore you can run the script, you have to make it executable, as shown below:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":5,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":5,\"nbrPlacementsScanned\":6,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":277} --><\/p>\n<pre>chmod +x fcnt.sh<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":5,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":5,\"nbrPlacementsScanned\":6,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":293} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:8.8235294117647%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/9-7.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/9-7.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/9-7.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/9-7.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/9-7.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"57\" alt=\"chmod +x fcnt.sh in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/9-7.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":5,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":5,\"nbrPlacementsScanned\":6,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":533} --><br \/>\nType the following to run the script:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":5,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":5,\"nbrPlacementsScanned\":6,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":570} --><\/p>\n<pre>.\/fcnt.sh<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":5,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":5,\"nbrPlacementsScanned\":6,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":579} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:15.015479876161%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/10-7.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/10-7.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/10-7.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/10-7.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/10-7.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"97\" alt=\".\/fcnt.sh in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/10-7.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":5,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":5,\"nbrPlacementsScanned\":6,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":819} --><br \/>\nThis prints the number of files in the <code>\/dev<\/code> directory. Here&#8217;s how it works:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":5,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":5,\"nbrPlacementsScanned\":6,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":898} --><\/p>\n<ul>\n<li> A variable called <code>folder_to_count<\/code> is defined, and it&#8217;s set to hold the string &#8220;\/dev.&#8221; <\/li>\n<li> Another variable, called <code>file_count<\/code>, is defined. This variable takes its value from a command substitution. This is the command phrase between the parentheses <code>$( )<\/code>. Note there&#8217;s a dollar sign <code>$<\/code> before the first parenthesis. This construct <code>$( )<\/code> evaluates the commands within the parentheses, and then returns their final value. In this example, that value is assigned to the <code>file_count<\/code> variable. As far as the <code>file_count<\/code> variable is concerned, it&#8217;s passed a value to hold; it isn&#8217;t concerned with how the value was obtained. <\/li>\n<li> The command evaluated in the command substitution performs an <code>ls<\/code> file listing on the directory in the <code>folder_to_count<\/code> variable, which has been set to &#8220;\/dev.&#8221; So, the script executes the command &#8220;ls \/dev.&#8221; <\/li>\n<li> The output from this command is piped into the <code>wc <\/code>command. The <code>-l<\/code> (line count) option causes <code>wc<\/code> to <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/man7.org\/linux\/man-pages\/man1\/wc.1.html\">count the number of lines<\/a> in the output from the <code>ls<\/code> command. As each file is listed on a separate line, this is the count of files and subdirectories in the &#8220;\/dev&#8221; directory. This value is assigned to the <code>file_count<\/code> variable. <\/li>\n<li> The final line uses echo to output the result. <\/li>\n<\/ul>\n<p><!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":5,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":5,\"nbrPlacementsScanned\":6,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":2152} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":6,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":6,\"nbrPlacementsScanned\":6,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><br \/>\nBut this only works for the &#8220;\/dev&#8221; directory. How can we make the script work with any directory? All it takes is one small change.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":6,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":6,\"nbrPlacementsScanned\":7,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":141} --><\/p>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":6,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":6,\"nbrPlacementsScanned\":7,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":141} --><\/p>\n<h2 id=\"how-to-use-command-line-parameters-in-scripts\"><span class=\"ez-toc-section\" id=\"How_to_Use_Command_Line_Parameters_in_Scripts\"><\/span> How to Use Command Line Parameters in Scripts <span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Many commands, such as <code>ls<\/code> and <code>wc<\/code>, take command line parameters. These provide information to the command, so it knows what you want it to do. If you want <code>ls<\/code> to work on your home directory and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/man7.org\/linux\/man-pages\/man1\/ls.1.html\">also to show hidden files<\/a>, you can use the following command, where the tilde <code>~<\/code> and the <code>-a<\/code> (all) option are command line parameters:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":6,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":6,\"nbrPlacementsScanned\":7,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":465} --><\/p>\n<pre>ls ~ -a<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":6,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":6,\"nbrPlacementsScanned\":7,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":472} --><br \/>\nOur scripts can accept command line parameters. They&#8217;re referenced as <code>$1<\/code> for the first parameter, <code>$2<\/code> as the second, and so on, up to <code>$9<\/code> for the ninth parameter. (Actually, there&#8217;s a <code>$0<\/code>, as well, but that&#8217;s reserved to always hold the script.)<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":6,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":6,\"nbrPlacementsScanned\":7,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":726} --><br \/>\nYou can reference command line parameters in a script just as you would regular variables. Let&#8217;s modify our script, as shown below, and save it with the new name <code>fcnt2.sh<\/code>:<br \/>\n<!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":6,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":6,\"nbrPlacementsScanned\":7,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":901} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":7,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":7,\"nbrPlacementsScanned\":7,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><\/p>\n<pre>#!\/bin\/bashfolder_to_count=$1file_count=$(ls $folder_to_count | wc -l)echo $file_count files in $folder_to_count<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":7,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":7,\"nbrPlacementsScanned\":8,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":112} --><br \/>\nThis time, the <code>folder_to_count<\/code> variable is assigned the value of the first command line parameter, <code>$1<\/code>.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":7,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":7,\"nbrPlacementsScanned\":8,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":214} --><br \/>\nThe rest of the script works exactly as it did before. Rather than a specific solution, your script is now a general one. You can use it on any directory because it&#8217;s not hardcoded to work only with &#8220;\/dev.&#8221;<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":7,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":7,\"nbrPlacementsScanned\":8,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":434} --><br \/>\nHere&#8217;s how you make the script executable:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":7,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":7,\"nbrPlacementsScanned\":8,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":480} --><\/p>\n<pre>chmod +x fcnt2.sh<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":7,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":7,\"nbrPlacementsScanned\":8,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":497} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:8.8235294117647%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/11-7.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/11-7.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/11-7.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/11-7.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/11-7.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"57\" alt=\"chmod +x fcnt2.sh in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/11-7.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":7,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":7,\"nbrPlacementsScanned\":8,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":737} --><br \/>\nNow, try it with a few directories. You can do &#8220;\/dev&#8221; first to make sure you get the same result as before. Type the following:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":7,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":7,\"nbrPlacementsScanned\":8,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":874} --><\/p>\n<pre>.\/fnct2.sh \/dev<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":7,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":7,\"nbrPlacementsScanned\":8,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":889} --><\/p>\n<pre>.\/fnct2.sh \/etc<\/pre>\n<p><!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":7,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":7,\"nbrPlacementsScanned\":8,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":904} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":8,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":8,\"nbrPlacementsScanned\":8,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><\/p>\n<pre>.\/fnct2.sh \/bin<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":8,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":8,\"nbrPlacementsScanned\":9,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":15} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:25.851393188854%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/12-8.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/12-8.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/12-8.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/12-8.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/12-8.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"167\" alt=\".\/fnct2.sh \/dev in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/12-8.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":8,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":8,\"nbrPlacementsScanned\":9,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":255} --><br \/>\nYou get the same result (207 files) as before for the &#8220;\/dev&#8221; directory. This is encouraging, and you get directory-specific results for each of the other command line parameters.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":8,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":8,\"nbrPlacementsScanned\":9,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":443} --><br \/>\nTo shorten the script, you could dispense with the variable, <code>folder_to_count<\/code>, altogether, and just reference <code>$1<\/code> throughout, as follows:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":8,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":8,\"nbrPlacementsScanned\":9,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":578} --><\/p>\n<pre>#!\/bin\/bash file_count=$(ls $1 wc -l) echo $file_count files in $1<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":8,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":8,\"nbrPlacementsScanned\":9,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":644} --><\/p>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":8,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":8,\"nbrPlacementsScanned\":9,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":644} --><\/p>\n<h2 id=\"working-with-special-variables\"><span class=\"ez-toc-section\" id=\"Working_with_Special_Variables\"><\/span> Working with Special Variables <span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>We mentioned <code>$0<\/code>, which is always set to the filename of the script. This allows you to use the script to do things like print its name out correctly, even if it&#8217;s renamed. This is useful in logging situations, in which you want to know the name of the process that added an entry.<br \/>\n<!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":8,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":8,\"nbrPlacementsScanned\":9,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":928} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":9,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":9,\"nbrPlacementsScanned\":9,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><br \/>\nThe following are the other special preset variables:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":9,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":9,\"nbrPlacementsScanned\":10,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":53} --><\/p>\n<ul>\n<li> <strong>$#<\/strong>: How many command line parameters were passed to the script. <\/li>\n<li> <strong>$@<\/strong>: All the command line parameters passed to the script. <\/li>\n<li> <strong>$?<\/strong>: The exit status of the last process to run. <\/li>\n<li> <strong>$$<\/strong>: The Process ID (PID) of the current script. <\/li>\n<li> <strong>$USER<\/strong>: The username of the user executing the script. <\/li>\n<li> <strong>$HOSTNAME<\/strong>: The hostname of the computer running the script. <\/li>\n<li> <strong>$SECONDS<\/strong>: The number of seconds the script has been running for. <\/li>\n<li> <strong>$RANDOM<\/strong>: Returns a random number. <\/li>\n<li> <strong>$LINENO<\/strong>: Returns the current line number of the script. <\/li>\n<\/ul>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":9,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":9,\"nbrPlacementsScanned\":10,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":559} -->You want to see all of them in one script, don&#8217;t you? You can! Save the following as a text file called, <code>special.sh<\/code>:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":9,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":9,\"nbrPlacementsScanned\":10,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":679} --><\/p>\n<pre>#!\/bin\/bashecho \"There were $# command line parameters\"echo \"They are: $@\"echo \"Parameter 1 is: $1\"echo \"The script is called: $0\"# any old process so that we can report on the exit statuspwdecho \"pwd returned $?\"echo \"This script has Process ID $$\"echo \"The script was started by $USER\"echo \"It is running on $HOSTNAME\"sleep 3echo \"It has been running for $SECONDS seconds\"echo \"Random number: $RANDOM\"echo \"This is line number $LINENO of the script\"<\/pre>\n<p><!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":9,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":9,\"nbrPlacementsScanned\":10,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":1240} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":10,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":10,\"nbrPlacementsScanned\":10,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><br \/>\nType the following to make it executable:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":10,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":10,\"nbrPlacementsScanned\":11,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":41} --><\/p>\n<pre>chmod +x special.sh<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":10,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":10,\"nbrPlacementsScanned\":11,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":60} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:8.8235294117647%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/13-5.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/13-5.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/13-5.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/13-5.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/13-5.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"57\" alt=\"fig13 in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/13-5.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":10,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":10,\"nbrPlacementsScanned\":11,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":300} --><br \/>\nNow, you can run it with a bunch of different command line parameters, as shown below.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":10,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":10,\"nbrPlacementsScanned\":11,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":386} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:47.523219814241%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/14-5.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/14-5.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/14-5.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/14-5.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/14-5.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"307\" alt=\".\/special.sh alpha bravo charlie 56 2048 Thursday in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/14-5.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":10,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":10,\"nbrPlacementsScanned\":11,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":626} --><\/p>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":10,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":10,\"nbrPlacementsScanned\":11,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":626} --><\/p>\n<h2 id=\"environment-variables\"><span class=\"ez-toc-section\" id=\"Environment_Variables\"><\/span> Environment Variables <span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Bash uses environment variables to define and record the properties of the environment it creates when it launches. These hold information Bash can readily access, such as your username, locale, the number of commands your history file can hold, your default editor, and lots more.<br \/>\n<!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":10,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":10,\"nbrPlacementsScanned\":11,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":907} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":11,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":11,\"nbrPlacementsScanned\":11,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><br \/>\nTo see the active environment variables in your Bash session, use this command:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":11,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":11,\"nbrPlacementsScanned\":12,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":79} --><\/p>\n<pre>env | less<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":11,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":11,\"nbrPlacementsScanned\":12,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":89} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:8.8235294117647%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/15-6.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/15-6.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/15-6.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/15-6.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/15-6.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"57\" alt=\"env | less in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/15-6.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":11,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":11,\"nbrPlacementsScanned\":12,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":329} --><br \/>\nIf you scroll through the list, you might find some that would be useful to reference in your scripts.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":11,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":11,\"nbrPlacementsScanned\":12,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":431} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:59.133126934985%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/16-5.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/16-5.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/16-5.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/16-5.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/16-5.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"382\" alt=\"List of environment variables in less in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/16-5.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":11,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":11,\"nbrPlacementsScanned\":12,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":671} --><\/p>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":11,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":11,\"nbrPlacementsScanned\":12,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":671} --><\/p>\n<h2 id=\"how-to-export-variables\"><span class=\"ez-toc-section\" id=\"How_to_Export_Variables\"><\/span> How to Export Variables <span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When a script runs, it&#8217;s in its own process, and the variables it uses cannot be seen outside of that process. If you want to share a variable with another script that your script launches, you have to export that variable. We&#8217;ll show you how to this with two scripts.<br \/>\n<!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":11,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":11,\"nbrPlacementsScanned\":12,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":947} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":12,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":12,\"nbrPlacementsScanned\":12,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><br \/>\nFirst, save the following with the filename <code>script_one.sh<\/code>:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":12,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":12,\"nbrPlacementsScanned\":13,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":58} --><\/p>\n<pre>#!\/bin\/bashfirst_var=alphasecond_var=bravo# check their valuesecho \"$0: first_var=$first_var, second_var=$second_var\"export first_varexport second_var.\/script_two.sh# check their values againecho \"$0: first_var=$first_var, second_var=$second_var\"<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":12,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":12,\"nbrPlacementsScanned\":13,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":324} --><br \/>\nThis creates two variables, <code>first_var<\/code> and <code>second_var<\/code>, and it assigns some values. It prints these to the terminal window, exports the variables, and calls <code>script_two.sh<\/code>. When <code>script_two.sh<\/code> terminates, and process flow returns to this script, it again prints the variables to the terminal window. Then, you can see if they changed.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":12,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":12,\"nbrPlacementsScanned\":13,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":654} --><br \/>\nThe second script we&#8217;ll use is <code>script_two.sh<\/code>. This is the script that <code>script_one.sh<\/code>calls. Type the following:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":12,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":12,\"nbrPlacementsScanned\":13,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":767} --><\/p>\n<pre>#!\/bin\/bash# check their valuesecho \"$0: first_var=$first_var, second_var=$second_var\"# set new valuesfirst_var=charliesecond_var=delta# check their values againecho \"$0: first_var=$first_var, second_var=$second_var\"<\/pre>\n<p><!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":12,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":12,\"nbrPlacementsScanned\":13,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":1003} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":13,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":13,\"nbrPlacementsScanned\":13,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><br \/>\nThis second script prints the values of the two variables, assigns new values to them, and then prints them again.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":13,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":13,\"nbrPlacementsScanned\":14,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":114} --><br \/>\nTo run these scripts, you have to type the following to make them executable:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":13,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":13,\"nbrPlacementsScanned\":14,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":191} --><\/p>\n<pre>chmod +x script_one.shchmod +x script_two.sh<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":13,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":13,\"nbrPlacementsScanned\":14,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":235} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:14.751552795031%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/17-6.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/17-6.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/17-6.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/17-6.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/17-6.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"644\" class=\"lazyload\" height=\"95\" alt=\"chmod +x script_one.sh in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/17-6.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":13,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":13,\"nbrPlacementsScanned\":14,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":475} --><br \/>\nAnd now, type the following to launch <code>script_one.sh<\/code>:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":13,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":13,\"nbrPlacementsScanned\":14,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":527} --><\/p>\n<pre>.\/script_one.sh<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":13,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":13,\"nbrPlacementsScanned\":14,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":542} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:22.515527950311%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/18-6.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/18-6.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/18-6.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/18-6.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/18-6.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"644\" class=\"lazyload\" height=\"145\" alt=\".\/script_one.sh in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/18-6.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":13,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":13,\"nbrPlacementsScanned\":14,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":782} --><br \/>\nThis is what the output tells us:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":13,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":13,\"nbrPlacementsScanned\":14,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":815} --><\/p>\n<ul>\n<li> <strong>script_one.sh<\/strong> prints the values of the variables, which are alpha and bravo. <\/li>\n<li> <strong>script_two.sh<\/strong> prints the values of the variables (alpha and bravo) as it received them. <\/li>\n<li> <strong>script_two.sh<\/strong> changes them to charlie and delta. <\/li>\n<li> <strong>script_one.sh<\/strong> prints the values of the variables, which are still alpha and bravo. <\/li>\n<\/ul>\n<p><!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":13,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":13,\"nbrPlacementsScanned\":14,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":1121} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":14,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":14,\"nbrPlacementsScanned\":14,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><br \/>\nWhat happens in the second script, stays in the second script. It&#8217;s like copies of the variables are sent to the second script, but they&#8217;re discarded when that script exits. The original variables in the first script aren&#8217;t altered by anything that happens to the copies of them in the second.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":14,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":14,\"nbrPlacementsScanned\":15,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":305} --><\/p>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":14,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":14,\"nbrPlacementsScanned\":15,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":305} --><\/p>\n<h2 id=\"how-to-quote-variables\"><span class=\"ez-toc-section\" id=\"How_to_Quote_Variables\"><\/span> How to Quote Variables <span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You might have noticed that when scripts reference variables, they&#8217;re in quotation marks <code>\"<\/code>. This allows variables to be referenced correctly, so their values are used when the line is executed in the script.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":14,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":14,\"nbrPlacementsScanned\":15,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":521} --><br \/>\nIf the value you assign to a variable includes spaces, they must be in quotation marks when you assign them to the variable. This is because, by default, Bash uses a space as a delimiter.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":14,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":14,\"nbrPlacementsScanned\":15,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":708} --><br \/>\nHere&#8217;s an example:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":14,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":14,\"nbrPlacementsScanned\":15,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":730} --><\/p>\n<pre>site_name=How-To Geek<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":14,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":14,\"nbrPlacementsScanned\":15,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":751} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:20.433436532508%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/19-6.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/19-6.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/19-6.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/19-6.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/19-6.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"132\" alt=\"site_name=How-To Geek in a terminal window\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/19-6.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":14,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":14,\"nbrPlacementsScanned\":15,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":991} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":15,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":15,\"nbrPlacementsScanned\":15,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><br \/>\nBash sees the space before &#8220;Geek&#8221; as an indication that a new command is starting. It reports that there is no such command, and abandons the line. <code>echo<\/code> shows us that the <code>site_name<\/code> variable holds nothing \u2014 not even the &#8220;How-To&#8221; text.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":15,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":15,\"nbrPlacementsScanned\":16,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":259} --><br \/>\nTry that again with quotation marks around the value, as shown below:<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":15,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":15,\"nbrPlacementsScanned\":16,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":328} --><\/p>\n<pre>site_name=\"How-To Geek\"<\/pre>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":15,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":15,\"nbrPlacementsScanned\":16,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":361} --><\/p>\n<div class=\"body-img landscape\">\n<div class=\"responsive-img image-expandable img-article-item\" style=\"padding-bottom:18.885448916409%\" data-img-url=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/20-4.png\" data-modal-id=\"single-image-modal\" data-modal-container-id=\"single-image-modal-container\" data-img-caption=\"null\">\n<figure><picture><!--[if IE 9]> <video style=\"display: none;\"><![endif]--><source media=\"(min-width: 1024px)\" sizes=\"750px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/20-4.png?q=50&amp;fit=crop&amp;w=750&amp;dpr=1.5\"\/><source media=\"(min-width: 768px)\" sizes=\"943px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/20-4.png?q=50&amp;fit=crop&amp;w=943&amp;dpr=1.5\"\/><source media=\"(min-width: 481px)\" sizes=\"767px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/20-4.png?q=50&amp;fit=crop&amp;w=767&amp;dpr=1.5\"\/><source media=\"(min-width: 0px)\" sizes=\"480px\" data-srcset=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/20-4.png?q=50&amp;fit=crop&amp;w=480&amp;dpr=1.5\"\/><!--[if IE 9]><\/video><![endif]--><img loading=\"lazy\" decoding=\"async\" width=\"646\" class=\"lazyload\" height=\"122\" alt=\"site_name=\" how-to=\"\" geek=\"\" in=\"\" a=\"\" terminal=\"\" window=\"\" style=\"display:block;height:auto;max-width:100%;\" src=\"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2019\/09\/20-4.png\"\/><\/picture><\/figure>\n<\/div><\/div>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":15,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":15,\"nbrPlacementsScanned\":16,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":601} --><br \/>\nThis time, it&#8217;s recognized as a single value and assigned correctly to the <code>site_name<\/code> variable.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":15,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":15,\"nbrPlacementsScanned\":16,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":699} --><\/p>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":15,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":15,\"nbrPlacementsScanned\":16,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":699} --><\/p>\n<h2 id=\"echo-is-your-friend\"><span class=\"ez-toc-section\" id=\"echo_Is_Your_Friend\"><\/span> echo Is Your Friend <span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>It can take some time to get used to command substitution, quoting variables, and remembering when to include the dollar sign.<br \/>\n<!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":15,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":15,\"nbrPlacementsScanned\":16,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":825} --><br \/>\nBefore you hit Enter and execute a line of Bash commands, try it with <code>echo<\/code> in front of it. This way, you can make sure what&#8217;s going to happen is what you want. You can also catch any mistakes you might have made in the syntax.<br \/>\n<!-- Repeatable debug data: {\"injection\":\"before\",\"adPosition\":15,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":15,\"nbrPlacementsScanned\":16,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":1055} --><!-- Zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"after\",\"adPosition\":16,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":16,\"nbrPlacementsScanned\":16,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":0} --><\/p>\n<p><!-- No repeatable ad for zone: character count repeatable. --><!-- Repeatable debug data: {\"injection\":\"none\",\"adPosition\":16,\"startingPoint\":1,\"skipEvery\":null,\"nbrPlacementFilledEachSkip\":16,\"nbrPlacementsScanned\":17,\"ruleCount\":900,\"degradationStartingPoint\":2,\"actualCount\":320} --><\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.howtogeek.com\/442332\/how-to-work-with-variables-in-bash\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Variables are vital if you want to write scripts and understand what that code you&#8217;re about to cut and paste from the web will do to your Linux computer. We&#8217;ll get you started! Variables 101 Variables are named symbols that represent either a string or numeric value. When you use them in commands and expressions,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":586813,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/static1.howtogeekimages.com\/wordpress\/wp-content\/uploads\/2023\/07\/52971071687_d038f51da7_o.jpg","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-586812","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/586812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=586812"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/586812\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/586813"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=586812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=586812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=586812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}