{"id":12297,"date":"2023-06-11T10:48:13","date_gmt":"2023-06-11T10:48:13","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=12297"},"modified":"2024-01-11T03:06:59","modified_gmt":"2024-01-11T03:06:59","slug":"bash-input-argument","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/","title":{"rendered":"How to Use Input Argument in Bash [With 4 Practical Examples]"},"content":{"rendered":"<p style=\"text-align: justify;\">In Bash Scripting, <strong>input arguments<\/strong> refer to the <strong>values <\/strong>that are passed to a Bash script or function when it is executed. For instance, let\u2019s say you are writing a script that sums up two numbers and shows the output. Here, you need to pass those two numbers to the script and you can use the Bash input argument for that purpose. Bash Input Argument can be accessed using <strong>$1<\/strong>, <strong>$2<\/strong>, <strong>$3<\/strong> etc where <strong>$1<\/strong> is the <strong>first argument<\/strong>, <strong>$2<\/strong> <strong>second <\/strong>and so forth.<\/p>\n<p><span style=\"font-weight: 400;\"><div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Practice-Files_Bash-Input-Argument.zip\" class=\"su-button su-button-style-default\" style=\"color:#000000;background-color:#E8F9FF;border-color:#bac8cc;border-radius:56px\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color:#000000;padding:8px 26px;font-size:20px;line-height:30px;border-color:#effbff;border-radius:56px;text-shadow:0px 0px 0px #000000\"><i class=\"sui sui-download\" style=\"font-size:20px;color:#1AA1D6\"><\/i> Practice Files\u00a0to Use Input Argument in Bash<\/span><\/a><\/div><\/span><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" 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: #999;color:#999\" 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><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#4_Practical_Examples_of_Input_Argument_in_Bash\" >4 Practical Examples of Input Argument in Bash<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#1_Sum_up_Two_Numbers_in_Bash_Using_Input_Argument\" >1. Sum up Two Numbers in Bash Using Input Argument<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#2_Take_User_Information_Using_Bash_Input_Argument\" >2. Take User Information Using Bash Input Argument<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#3_Check_If_a_File_Exists_Using_Bash_Input_Argument\" >3. Check If a File Exists Using Bash Input Argument<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#4_Take_Input_Argument_With_Flags_in_Bash\" >4. Take Input Argument With Flags in Bash<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#People_Also_Ask\" >People Also Ask<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#What_is_argument_in_shell_script\" >What is argument in shell script?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#How_to_take_input_arguments_in_shell_script\" >How to take input arguments in shell script?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#What_is_1_and_2_in_shell_script\" >What is $1 and $2 in shell script?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#What_is_0_in_bash\" >What is $0 in bash?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"4_Practical_Examples_of_Input_Argument_in_Bash\"><\/span>4 Practical Examples of Input Argument in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In this section, I will provide some examples of Bash input argument. To grasp the concept, do the examples by hand.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Sum_up_Two_Numbers_in_Bash_Using_Input_Argument\"><\/span>1. Sum up Two Numbers in Bash Using Input Argument<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In this example, I will show you how to <strong>sum <\/strong>two numbers where I will take input from the user using Bash input argument:<\/p>\n<ol>\n<li>At first, launch an <strong>Ubuntu Terminal<\/strong>.<\/li>\n<li>Write the following command to <strong>open <\/strong>a file in <strong>Nano<\/strong>:\n<pre><code class=\"language-bash\" data-line=\"\">nano sum.sh<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<ul>\n<li><a href=\"https:\/\/linuxsimply.com\/nano-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>nano<\/strong><\/a>: Opens a file in the Nano text editor.<\/li>\n<li><strong>sh<\/strong>: Name of the file.<\/li>\n<\/ul>\n<\/div><\/div><img decoding=\"async\" class=\"aligncenter wp-image-12367 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/1.opening-sum-in-nano.png\" alt=\"Opening &quot;sum.sh&quot; file in Nano for &quot;Bash Input Argument&quot;\" width=\"482\" height=\"77\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/1.opening-sum-in-nano.png 482w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/1.opening-sum-in-nano-300x48.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/1.opening-sum-in-nano-764x122.png 764w\" sizes=\"(max-width: 482px) 100vw, 482px\" \/><\/li>\n<li>Copy the script mentioned below:\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nnumber1=$1\nnumber2=$2\n\nsum=$((number1 + number2))\necho &quot;The sum of $number1 and $number2 is: $sum&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">Here <strong>#!\/bin\/bash <\/strong>is called <strong>Shebang<\/strong> that specifies the <strong>interpreter<\/strong>. In <code class=\"\" data-line=\"\">number1=$1<\/code>,<strong> $1<\/strong> denotes the <strong>first argument<\/strong> and the first argument ($1) is stored in the <strong>variable number1<\/strong>. Similarly, <code class=\"\" data-line=\"\">$2<\/code> denotes <strong>second argument <\/strong>and is stored in the <strong>variable number2<\/strong>.<\/p>\n<p style=\"text-align: justify;\">Now in <code class=\"\" data-line=\"\">sum=$((number1 + number2))<\/code>, <strong>$(())<\/strong> is <strong>arithmetic expansion<\/strong>, which performs mathematical calculations within double parentheses. In this line, the summation of number1 and number2 is stored in the <strong>variable sum<\/strong>. Finally, in <strong>echo &#8220;The sum of $number1 and $number2 is: $sum&#8221;<\/strong>, the <a href=\"https:\/\/linuxsimply.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a> is used to print the output. Here the <code class=\"\" data-line=\"\">$<\/code> sign before variables ($number1, $number2, $sum), <strong>substitutes <\/strong>the variables with <strong>actual <\/strong>values.<\/p>\n<\/div><\/div><\/li>\n<li>Press <strong>CTRL+O<\/strong> and <strong>ENTER <\/strong>to save the file; <strong>CTRL+X<\/strong> to exit.<\/li>\n<li>Use the following command to make the file executable:\n<pre><code class=\"language-bash\" data-line=\"\">chmod u+x sum.sh<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<ul>\n<li><a href=\"https:\/\/linuxsimply.com\/chmod-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>chmod<\/strong><\/a>: Changes permissions.<\/li>\n<li><strong>u+x<\/strong>: Giving the owner executing permission.<\/li>\n<li><strong>sh<\/strong>: Name of the script.<\/div><\/div><\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12368 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/2.chmod-sum-script.png\" alt=\"Giving executing permission to sum.sh file\" width=\"574\" height=\"71\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/2.chmod-sum-script.png 574w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/2.chmod-sum-script-300x37.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/2.chmod-sum-script-760x94.png 760w\" sizes=\"(max-width: 574px) 100vw, 574px\" \/><\/li>\n<li>Run the script by the following command:\n<pre><code class=\"language-bash\" data-line=\"\">.\/sum.sh 3 7<\/code><\/pre>\n<div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#E8F9FC;border-color:#ffffff;color:#333333;\"><strong>Note:<\/strong> Here 3 and 7 are input arguments.<\/div><\/div><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-12369 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/3.running-sum-script.png\" alt=\"Running sum.sh file for &quot;Bash Input Argument&quot;\" width=\"543\" height=\"102\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/3.running-sum-script.png 543w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/3.running-sum-script-300x56.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/3.running-sum-script-767x144.png 767w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/>In the output, you can see the sum of 3 and 7 is <strong>10<\/strong>.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"2_Take_User_Information_Using_Bash_Input_Argument\"><\/span>2. Take User Information Using Bash Input Argument<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In this example, I will <strong>take <\/strong>user information using the Bash input argument and <strong>print <\/strong>them on the terminal:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\necho &quot;Name: $1&quot;\necho &quot;Age: $2&quot;\necho &quot;City: $3&quot;\necho &quot;Country: $4&quot;\necho &quot;Profession: $5&quot;<\/code><\/pre>\n<p><span style=\"font-weight: 400;\"><div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\"><\/span><\/p>\n<p>In this script, the inputs are stored in special variables <strong>$1<\/strong>,<strong> $2<\/strong>, <strong>$3<\/strong>, <strong>$4<\/strong>, <strong>$5<\/strong>. Then the inputs are printed on the terminal using the <code class=\"\" data-line=\"\">echo<\/code>\u00a0command.<\/p>\n<p><span style=\"font-weight: 400;\"><\/div><\/div><\/span><\/p>\n<p>Now, run the <strong>script <\/strong>by the following command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/user_info.sh &quot;Walid Al Asad&quot; 26 Dhaka Bangladesh Blogger<\/code><\/pre>\n<p><span style=\"font-weight: 400;\"><div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#E8F9FC;border-color:#ffffff;color:#333333;\"><\/span><\/p>\n<p><strong>Note:<\/strong> The double quotation denotes <strong>Walid Al Asad<\/strong> as a single entity.<\/p>\n<p><span style=\"font-weight: 400;\"><\/div><\/div><\/span><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-12370 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/4.Running-user_info.png\" alt=\"Output of user_info.sh\" width=\"825\" height=\"160\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/4.Running-user_info.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/4.Running-user_info-300x58.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/4.Running-user_info-763x148.png 763w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/>In the output, the script is showing user information which was given as arguments.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Check_If_a_File_Exists_Using_Bash_Input_Argument\"><\/span>3. Check If a File Exists Using Bash Input Argument<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Here I will pass a <strong>filename <\/strong>as an input argument and check if the file <strong>exits <\/strong>or not:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nfilename=$1\n\nif [[ -e &quot;$filename&quot; ]]\nthen\necho &quot;The file $filename exists.&quot;\nelse\necho &quot;The file $filename does not exist.&quot;\nfi<\/code><\/pre>\n<p><span style=\"font-weight: 400;\"><div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\"><\/span><\/p>\n<p style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">filename=$1<\/code> line stores the argument in the <strong>filename variable<\/strong>. In <strong>if else<\/strong> statement,\u00a0 <code class=\"\" data-line=\"\">-e<\/code> checks if a <strong>file <\/strong>or <strong>directory exists<\/strong>. If the condition is true, it shows the file exists, otherwise shows the file doesn\u2019t exits. In addition, here <strong>$filename<\/strong> is a way to access the filename variable. It is enclosed in <strong>double quotation (\u201c\u201d)<\/strong> to handle spaces and special characters.<\/p>\n<p><span style=\"font-weight: 400;\"><\/div><\/div><\/span><\/p>\n<p>Now run the script by the following command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/check_file.sh hello.txt<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-12371 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/5.running-check_info.png\" alt=\"Output of file.sh script\" width=\"700\" height=\"107\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/5.running-check_info.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/5.running-check_info-300x46.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/5.running-check_info-765x117.png 765w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>As there is no \u201c<strong>hello.txt<\/strong>\u201d file in my directory, the output is showing that the file doesn\u2019t exist.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Take_Input_Argument_With_Flags_in_Bash\"><\/span>4. Take Input Argument With Flags in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Here, I will show you how to take arguments with <strong>flags<\/strong>. What is a flag? A flag <strong>modifies <\/strong>the behavior of a command or script. I will use <code class=\"\" data-line=\"\">getopts<\/code> command here which provides a way to handle flags. My script will take a <strong>filename <\/strong>and a <strong>number <\/strong>as output and <strong>print <\/strong>them on the terminal. Moreover, it will throw an <strong>error <\/strong>if an option is <strong>invalid:<\/strong><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nwhile getopts &quot;f:n:&quot; opt; do\ncase $opt in\n\nf)\nfilename=$OPTARG\necho &quot;File: $filename&quot;\n;;\n\nn)\nnum=$OPTARG\necho &quot;Number: $num&quot;\n;;\n\n\\?)\necho &quot;Invalid option: -$OPTARG&quot;\n;;\n\nesac\ndone<\/code><\/pre>\n<p><span style=\"font-weight: 400;\"><div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\"><\/span><\/p>\n<p style=\"text-align: justify;\">The script starts with <strong>#!\/bin\/bash <\/strong>that specifies the interpreter. <code class=\"\" data-line=\"\">while getopts &quot;f:n:&quot; opt; do<\/code> starts a <strong>loop <\/strong>that uses the <code class=\"\" data-line=\"\">getopts<\/code> command to take options and arguments. Here are two options- \u201cf:\u201d and \u201cn:\u201d. The script expects two options: <code class=\"\" data-line=\"\">-f<\/code> followed by a <strong>filename<\/strong>, and <code class=\"\" data-line=\"\">-n<\/code> followed by a <strong>number<\/strong>. Moreover, the <strong>colon <\/strong>(\u201c:\u201d) indicates that the option requires an <strong>argument<\/strong>.<\/p>\n<p style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">f)<\/code> section assigns the <strong>argument <\/strong>(<strong>$OPTARG<\/strong>) of option \u201c-f\u201d to the <strong>variable filename<\/strong>. Then echoes the filename. Furthermore, the <code class=\"\" data-line=\"\">n)<\/code> section assigns the <strong>argument <\/strong>(<strong>$OPTARG<\/strong>) of option \u201c-n\u201d to the <strong>variable num<\/strong>. Then echoes the number. In addition, the <code class=\"\" data-line=\"\">\\?)<\/code>\u00a0pattern is used to handle the situation when a provided option is not recognized by the script. And then a line is printed indicating an <strong>invalid <\/strong>option was provided. Finally, <code class=\"\" data-line=\"\">esac<\/code> and <code class=\"\" data-line=\"\">done<\/code> end the \u201ccase\u201d statement and \u201cwhole\u201d statement respectively.<\/p>\n<p><span style=\"font-weight: 400;\"><\/div><\/div><\/span><\/p>\n<p>Execute the script by the following command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/flags.sh -f myfile.txt -n 10<\/code><\/pre>\n<p style=\"text-align: justify;\" data-wp-editing=\"1\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-12372\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/6.running-flags.png\" alt=\"\" width=\"825\" height=\"165\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/6.running-flags.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/6.running-flags-300x60.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/6.running-flags-765x153.png 765w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/>Here, the argument of flag \u201c-f\u201d is <strong>myfile.txt<\/strong>\u00a0and \u201c-n\u201d is <strong>10<\/strong>. And you can see <strong>myfile.txt<\/strong> and <strong>10<\/strong>\u00a0in the output.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In this article, I have tried my best to explain the Bash input argument. Practice the examples here. Hopefully, it will help you with your journey of Bash scripting.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"People_Also_Ask\"><\/span>People Also Ask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"What_is_argument_in_shell_script\"><\/span><span style=\"font-weight: 400;\">What is argument in shell script?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">An argument in shell script is a value that is passed to the script when it is executed. Arguments can be useful for making the script dynamic and responsive.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_take_input_arguments_in_shell_script\"><\/span><span style=\"font-weight: 400;\">How to take input arguments in shell script?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">To take input arguments in a shell script, you can use the special variables <strong>$1, $2, $3<\/strong>. By using those variables, you can access the <strong>first, second and third<\/strong> argument respectively.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_1_and_2_in_shell_script\"><\/span><span style=\"font-weight: 400;\">What is $1 and $2 in shell script?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\"><code class=\"\" data-line=\"\">$1<\/code> and <code class=\"\" data-line=\"\">$2<\/code> in shell script are positional parameters that hold the values passed to the script on the command line.<br \/>\n<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_0_in_bash\"><\/span><span style=\"font-weight: 400;\">What is $0 in bash?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\"><code class=\"\" data-line=\"\">$0<\/code> in bash is a special parameter that holds the name of the script. For instance, if your script name is <strong>myscript.sh<\/strong>, then $0 will be <strong>myscript.sh<\/strong>.<\/span><\/p>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"What is argument in shell script?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"An argument in shell script is a value that is passed to the script when it is executed. Arguments can be useful for making the script dynamic and responsive.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"How to take input arguments in shell script?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To take input arguments in a shell script, you can use the special variables $1, $2, $3. By using those variables, you can access the first, second and third argument respectively.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What is $1 and $2 in shell script?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"$1 and $2 in shell script are positional parameters that hold the values passed to the script on the command line.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What is $0 in bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"$0 in bash is a special parameter that holds the name of the script. For instance, if your script name is myscript.sh, then $0 will be myscript.sh.\"\n    }\n  }]\n}\n<\/script><\/p>\n<p><span style=\"font-size: 18pt; color: #003366;\"><strong>Related Articles<\/strong><\/span><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-parameter\/\" target=\"_blank\" rel=\"noopener\">How to Use Bash Input Parameter? [5 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/read-input\/\" target=\"_blank\" rel=\"noopener\">How to Read User Input in Bash [5 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/wait-for-input\/\" target=\"_blank\" rel=\"noopener\">How to Wait for User Input in Bash [With 4 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/read-csv\/\" target=\"_blank\" rel=\"noopener\">How to Read CSV Files in Bash? [2 Methods]<\/a><\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>&lt;&lt; Go Back to <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Input&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1065857,&quot;3&quot;:{&quot;1&quot;:0},&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/\" target=\"_blank\" rel=\"noopener\">Bash Input<\/a><\/span> | <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash I\/O&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1065857,&quot;3&quot;:{&quot;1&quot;:0},&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/\" target=\"_blank\" rel=\"noopener\">Bash I\/O<\/a><\/span> | <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Tutorial<\/a><\/strong><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;12297&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;10&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;4.9&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;4.9\\\/5 - (10 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;How to Use Input Argument in Bash [With 4 Practical Examples]&quot;,&quot;width&quot;:&quot;139.6&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 139.6px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            4.9\/5 - (10 votes)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>In Bash Scripting, input arguments refer to the values that are passed to a Bash script or function when it &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Use Input Argument in Bash [With 4 Practical Examples]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#more-12297\" aria-label=\"Read more about How to Use Input Argument in Bash [With 4 Practical Examples]\">Read more<\/a><\/p>\n","protected":false},"author":314893,"featured_media":12583,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[101],"class_list":["post-12297","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-bash-input","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Use Input Argument in Bash [With 4 Practical Examples]<\/title>\n<meta name=\"description\" content=\"Bash input argument is used to pass values to your scripts. This article shows how to access arguments using $1, $2, $3 variables.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use Input Argument in Bash [With 4 Practical Examples]\" \/>\n<meta property=\"og:description\" content=\"Bash input argument is used to pass values to your scripts. This article shows how to access arguments using $1, $2, $3 variables.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/walid.alasad.5\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-11T10:48:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-11T03:06:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Input-Argument1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Walid Al Asad\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Walid Al Asad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/\"},\"author\":{\"name\":\"Walid Al Asad\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/b54259fce1dc6e35d375984aff173ff0\"},\"headline\":\"How to Use Input Argument in Bash [With 4 Practical Examples]\",\"datePublished\":\"2023-06-11T10:48:13+00:00\",\"dateModified\":\"2024-01-11T03:06:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/\"},\"wordCount\":1132,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Bash-Input-Argument1.png\",\"keywords\":[\"bash input\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/\",\"name\":\"How to Use Input Argument in Bash [With 4 Practical Examples]\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Bash-Input-Argument1.png\",\"datePublished\":\"2023-06-11T10:48:13+00:00\",\"dateModified\":\"2024-01-11T03:06:59+00:00\",\"description\":\"Bash input argument is used to pass values to your scripts. This article shows how to access arguments using $1, $2, $3 variables.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Bash-Input-Argument1.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Bash-Input-Argument1.png\",\"width\":400,\"height\":400,\"caption\":\"Bash Input Argument\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/input-argument\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash Scripting Tutorial\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Bash I\\\/O\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Bash Input\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/input-output\\\/input\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to Use Input Argument in Bash [With 4 Practical Examples]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"name\":\"LinuxSimply\",\"description\":\"All About Linux\",\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linuxsimply.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\",\"name\":\"LinuxSimply\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"width\":355,\"height\":48,\"caption\":\"LinuxSimply\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/b54259fce1dc6e35d375984aff173ff0\",\"name\":\"Walid Al Asad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Walid-Al-Asad-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Walid-Al-Asad-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Walid-Al-Asad-II-96x96.png\",\"caption\":\"Walid Al Asad\"},\"description\":\"Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/walid.alasad.5\",\"https:\\\/\\\/www.instagram.com\\\/alasadwalid\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/walid-al-asad\\\/\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/walid\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Use Input Argument in Bash [With 4 Practical Examples]","description":"Bash input argument is used to pass values to your scripts. This article shows how to access arguments using $1, $2, $3 variables.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/","og_locale":"en_US","og_type":"article","og_title":"How to Use Input Argument in Bash [With 4 Practical Examples]","og_description":"Bash input argument is used to pass values to your scripts. This article shows how to access arguments using $1, $2, $3 variables.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/walid.alasad.5","article_published_time":"2023-06-11T10:48:13+00:00","article_modified_time":"2024-01-11T03:06:59+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Input-Argument1.png","type":"image\/png"}],"author":"Walid Al Asad","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Walid Al Asad","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/"},"author":{"name":"Walid Al Asad","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/b54259fce1dc6e35d375984aff173ff0"},"headline":"How to Use Input Argument in Bash [With 4 Practical Examples]","datePublished":"2023-06-11T10:48:13+00:00","dateModified":"2024-01-11T03:06:59+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/"},"wordCount":1132,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Input-Argument1.png","keywords":["bash input"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/","name":"How to Use Input Argument in Bash [With 4 Practical Examples]","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Input-Argument1.png","datePublished":"2023-06-11T10:48:13+00:00","dateModified":"2024-01-11T03:06:59+00:00","description":"Bash input argument is used to pass values to your scripts. This article shows how to access arguments using $1, $2, $3 variables.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Input-Argument1.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Input-Argument1.png","width":400,"height":400,"caption":"Bash Input Argument"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/input-argument\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxsimply.com\/"},{"@type":"ListItem","position":2,"name":"Bash Scripting Tutorial","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/"},{"@type":"ListItem","position":3,"name":"Bash I\/O","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/"},{"@type":"ListItem","position":4,"name":"Bash Input","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/"},{"@type":"ListItem","position":5,"name":"How to Use Input Argument in Bash [With 4 Practical Examples]"}]},{"@type":"WebSite","@id":"https:\/\/linuxsimply.com\/#website","url":"https:\/\/linuxsimply.com\/","name":"LinuxSimply","description":"All About Linux","publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxsimply.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linuxsimply.com\/#organization","name":"LinuxSimply","url":"https:\/\/linuxsimply.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","width":355,"height":48,"caption":"LinuxSimply"},"image":{"@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/b54259fce1dc6e35d375984aff173ff0","name":"Walid Al Asad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Walid-Al-Asad-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Walid-Al-Asad-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Walid-Al-Asad-II-96x96.png","caption":"Walid Al Asad"},"description":"Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio","sameAs":["https:\/\/www.facebook.com\/walid.alasad.5","https:\/\/www.instagram.com\/alasadwalid\/","https:\/\/www.linkedin.com\/in\/walid-al-asad\/"],"url":"https:\/\/linuxsimply.com\/author\/walid\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/12297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/users\/314893"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=12297"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/12297\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/12583"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=12297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=12297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=12297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}