{"id":37848,"date":"2024-02-28T02:57:45","date_gmt":"2024-02-28T02:57:45","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=37848"},"modified":"2024-04-23T03:57:34","modified_gmt":"2024-04-23T03:57:34","slug":"bash-first-argument","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/","title":{"rendered":"How to Use First Argument in Bash Script [5 Cases]"},"content":{"rendered":"<p style=\"text-align: justify;\">In Bash, $1 represents the first argument of a script. This means when users provide the first argument while executing a script, it is accessible within the script by the first positional parameter ($1). In this article, primarily I will show how to provide and access the first argument. Moreover, I will try to satiate users\u2019 various other queries related to the first argument in Bash.<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Practice_Files_bash-first-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> Files of First Argument in Bash<\/span><\/a><\/div>\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\/functions\/script-argument\/first-argument\/#How_to_Provide_the_First_Argument_in_Shell_Script\" >How to Provide the First Argument in Shell Script?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#How_to_Access_the_First_Argument_in_Bash_Script\" >How to Access the First Argument in Bash Script?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#5_Cases_of_Handling_First_Argument_in_Bash_Script\" >5 Cases of Handling First Argument in Bash Script<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#1_How_to_Check_the_Existence_of_the_First_Argument_in_Bash\" >1. How to Check the Existence of the First Argument in Bash<\/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\/functions\/script-argument\/first-argument\/#2_How_to_Pass_a_File_as_the_First_Input_Argument_in_Bash\" >2. How to Pass a File as the First Input Argument in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#3_Iterate_Over_Input_Arguments_Except_First_One\" >3. Iterate Over Input Arguments Except First One<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#4_Change_the_First_Argument_in_Bash_Script\" >4. Change the First Argument in Bash Script<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#5_How_to_Skip_the_First_Argument_in_Bash_Script\" >5. How to Skip the First Argument in Bash Script<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-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-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#How_to_check_if_the_first_argument_is_empty\" >How to check if the first argument is empty?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#What_is_the_difference_between_1_and\" >What is the difference between $1 and $@?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#How_to_store_the_first_argument_in_a_variable_in_Bash_script\" >How to store the first argument in a variable in Bash script?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#Why_is_1_in_a_function_not_printing_the_scripts_first_argument\" >Why is $1 in a function not printing the script&#8217;s first argument?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Provide_the_First_Argument_in_Shell_Script\"><\/span>How to Provide the First Argument in Shell Script?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To provide the first argument in a shell script, simply pass it as a command line argument while executing the script. For instance, if you have a script named \u201cmyscript.sh\u201d and want to provide \u201cLinux\u201d as the first argument, then execute the script as follows:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/myscript.sh Linux<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Access_the_First_Argument_in_Bash_Script\"><\/span>How to Access the First Argument in Bash Script?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To access the first argument in Bash script, use the first <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/positional-parameters\/\" target=\"_blank\" rel=\"noopener\"><strong>positional parameter<\/strong><\/a> <strong>$1<\/strong>. Here is a simple example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Print the first argument\necho &quot;First argument: $1&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>This Bash script prints out the first argument passed to it. It uses the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/echo-command\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a> to display the text &#8220;First argument: &#8221; followed by the value of <code class=\"\" data-line=\"\">$1<\/code>, which represents the first argument provided to the script.<\/p>\n<p style=\"text-align: justify;\"><\/div><\/div><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-37849\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/0.-Accessing-the-first-argument-in-Bash.png\" alt=\"Accessing the first argument in Bash\" width=\"601\" height=\"105\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/0.-Accessing-the-first-argument-in-Bash.png 601w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/0.-Accessing-the-first-argument-in-Bash-300x52.png 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/>Executing the script with the argument \u201cLinux\u201d shows the argument after the text \u201cFirst Argument: \u201d. Within the script, <strong>$1<\/strong> successfully refers to the first argument of the script.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"5_Cases_of_Handling_First_Argument_in_Bash_Script\"><\/span>5 Cases of Handling First Argument in Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Bash users often need to check the existence of the first argument in a script. Moreover, it is required to modify or skip the first argument occasionally. Therefore, handling the first argument effectively is an essential skill. The following discussion will highlight a few cases for effectively managing the first argument.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_How_to_Check_the_Existence_of_the_First_Argument_in_Bash\"><\/span>1. How to Check the Existence of the First Argument in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To check the existence of the first argument, compare whether the first argument ($1) is empty or not. Use an <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/\" target=\"_blank\" rel=\"noopener\"><strong>if statement<\/strong><\/a> with <strong>-z <\/strong>test operator for this purpose. Here&#8217;s an example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nif [ -z &quot;$1&quot; ]; then\n\u00a0\u00a0\u00a0 echo &quot;First argument doesn\u2019t exist or it\u2019s empty.&quot;\nelse\n\u00a0\u00a0\u00a0 echo &quot;First argument exists and its value is: $1&quot;\nfi<\/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>The <strong>if statement<\/strong> checks the length of the first argument ($1) using the <strong>-z<\/strong> operator. If the length is zero, it indicates that the first argument doesn\u2019t exist or is empty. On the other hand, a non-zero length of the first argument implies that the first argument exists.<\/p>\n<p style=\"text-align: justify;\"><\/div><\/div><img decoding=\"async\" class=\"aligncenter size-full wp-image-37850\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.-Checking-the-existence-of-the-first-argument-in-Bash.png\" alt=\"Checking the existence of the first argument in Bash\" width=\"700\" height=\"229\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.-Checking-the-existence-of-the-first-argument-in-Bash.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.-Checking-the-existence-of-the-first-argument-in-Bash-300x98.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>When the empty string <code class=\"\" data-line=\"\">&quot;&quot;<\/code> or no argument is provided to the script it shows that \u201cFirst argument doesn\u2019t exist or it\u2019s empty\u201d. However, when the argument \u201ca\u201d is parsed it displays that the first argument exists.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_How_to_Pass_a_File_as_the_First_Input_Argument_in_Bash\"><\/span>2. How to Pass a File as the First Input Argument in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Provide the file&#8217;s path as the first argument when running the script to pass a file as an input argument in a Bash script. Consider a file <strong>arg1.txt<\/strong> that contains some data:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#Users\nKenny\nAnita\nSmith\nMohammad<\/code><\/pre>\n<p>Now, write the following script that uses a <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/loop\/while-loop\/\" target=\"_blank\" rel=\"noopener\"><strong>while loop<\/strong><\/a> to process each line of the <strong>arg1.txt<\/strong> file after receiving it as the first argument:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nfile=&quot;$1&quot;\narr1=()\n\n# Skip the first line and read the rest of the file\nwhile read arg; do\n\u00a0 arr1+=(&quot;$arg&quot;)\ndone &lt; &lt;(tail -n +2 &quot;$file&quot;)\n# Print the elements of arr1\necho &quot;${arr1[@]}&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>This Bash script reads the contents of a file specified as the first argument, excluding the first line. It then populates an array, <code class=\"\" data-line=\"\">arr1<\/code>, with each line from the file. The script achieves this by using process substitution <code class=\"\" data-line=\"\">&lt;()<\/code> to provide the output of <code class=\"\" data-line=\"\">tail -n +2 &quot;$file&quot;<\/code> (which skips the first line of the file) as input to a while loop.<\/p>\n<p>Within the loop, each line is read and appended to the &#8220;arr1&#8221; array using the <code class=\"\" data-line=\"\">+=<\/code> operator. Finally, the script prints all elements of the &#8220;arr1&#8221; array using <code class=\"\" data-line=\"\">&quot;${arr1[@]}&quot;<\/code>.<\/p>\n<p style=\"text-align: justify;\"><\/div><\/div><img decoding=\"async\" class=\"aligncenter size-full wp-image-37851\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.-Passing-a-file-as-the-first-argument-in-Bash.png\" alt=\"Passing a file as the first argument in Bash\" width=\"618\" height=\"111\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.-Passing-a-file-as-the-first-argument-in-Bash.png 618w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.-Passing-a-file-as-the-first-argument-in-Bash-300x54.png 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/>Once executed the script prints the users listed in the &#8220;arg1.txt&#8221; file in an array by taking the file as the first argument.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Iterate_Over_Input_Arguments_Except_First_One\"><\/span>3. Iterate Over Input Arguments Except First One<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To iterate over input arguments except the first one in a Bash script, use a loop starting from the second argument onwards. The &#8220;$@&#8221; variable holds all the command line arguments. Looping over &#8220;${@:2}&#8221; allows you to access each argument individually, starting from the second argument($2). Here is an example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nfor i in &quot;${@:2}&quot;\ndo\n\u00a0\u00a0\u00a0 echo &quot;$i&quot;\ndone<\/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>This Bash script utilizes a <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/loop\/for-loop\/\" target=\"_blank\" rel=\"noopener\"><strong>for loop<\/strong><\/a> to iterate over all arguments passed to the script except for the first one. The loop iterates over the positional parameters starting from the second one using <code class=\"\" data-line=\"\">&quot;${@:2}&quot;<\/code>. For each iteration, it echoes the current argument (<code class=\"\" data-line=\"\">$i<\/code>). Essentially, this script prints out all arguments passed to the script, excluding the first one.<\/p>\n<p style=\"text-align: justify;\"><\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-37852\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.-Iterating-over-input-arguments-except-the-first-argument-in-Bash.png\" alt=\"Iterating over input arguments except the first argument in Bash\" width=\"609\" height=\"149\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.-Iterating-over-input-arguments-except-the-first-argument-in-Bash.png 609w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.-Iterating-over-input-arguments-except-the-first-argument-in-Bash-300x73.png 300w\" sizes=\"(max-width: 609px) 100vw, 609px\" \/>Once the script is executed it iterates over all the command line arguments except the first one. Therefore, among the three arguments 1, 4 and 5 the script prints the second and third arguments.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Change_the_First_Argument_in_Bash_Script\"><\/span>4. Change the First Argument in Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Use the set command to change the first argument in a Bash script. Rewriting the arguments after <strong>set &#8211; &#8211;<\/strong>, reset the command line arguments. The script below demonstrates how set built-in is used to modify the first command line argument:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Update the arguments as required\nset -- &quot;5&quot; &quot;${@:2}&quot;\n\n# Display the updated arguments\necho &quot;Updated arguments: $@&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>This Bash script updates its first argument by replacing it with &#8220;5&#8221; while keeping the rest unchanged. <code class=\"\" data-line=\"\">&quot;${@:2}&quot;<\/code> in the set command denotes all arguments except the first one. Finally, the script accesses the special variable <code class=\"\" data-line=\"\">$@<\/code> to show all the command line arguments including the modified first argument.<\/p>\n<p style=\"text-align: justify;\"><\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-37853\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.-Changing-the-first-argument-in-Bash.png\" alt=\"Changing the first argument in Bash\" width=\"652\" height=\"112\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.-Changing-the-first-argument-in-Bash.png 652w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.-Changing-the-first-argument-in-Bash-300x52.png 300w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/>Running the script with arguments \u201cNull\u201d, 7 and 13 changes the first argument \u201cNull\u201d to 5.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"5_How_to_Skip_the_First_Argument_in_Bash_Script\"><\/span>5. How to Skip the First Argument in Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Sometimes users want to get rid of the first argument passed to a Bash script. To skip the first argument, use the <strong>shift <\/strong>command to shift all the positional parameters to the left by one. Here&#8217;s how you can do it:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Skip the first argument\nshift\n\n# Now $1 refers to the second argument\necho &quot;Second argument: $1&quot;\n\n# Loop through all remaining arguments\necho &quot;Remaining arguments: $@&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>The script uses <strong>shift <\/strong>to skip the first positional argument passed to the script. Therefore, the second positional argument becomes the first argument and can be accessed using <code class=\"\" data-line=\"\">$1<\/code>. Finally, it also prints all the arguments using <code class=\"\" data-line=\"\">$@<\/code>, which represents all arguments passed to the script except the first one, as the first one has been shifted out.<\/p>\n<p style=\"text-align: justify;\"><\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-37854\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.-Skipping-the-first-argument-in-Bash.png\" alt=\"Skipping the first argument in Bash\" width=\"637\" height=\"102\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.-Skipping-the-first-argument-in-Bash.png 637w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.-Skipping-the-first-argument-in-Bash-300x48.png 300w\" sizes=\"(max-width: 637px) 100vw, 637px\" \/>Here, the script is executed with arguments 4,5 and 6. Due to the use of <strong>shift<\/strong>, all the arguments are shifted to the left by one position. As a result, the second argument becomes accessible by the first positional parameter ($1). Therefore, <strong>$@<\/strong> prints 5 and 6 effectively skipping the first argument(4) provided to the script.<\/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 conclusion, handling the first argument in Bash script is quite easy once you are familiar with the idea of positional parameters. The first positional parameter ($1) is used to access the first argument passed to a script. Moreover, the <strong>set<\/strong> built-in and <strong>shift<\/strong> command allows users to change or skip the first argument of a Bash script. I hope this article has helped you manipulate the first argument of your script.<\/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=\"How_to_check_if_the_first_argument_is_empty\"><\/span>How to check if the first argument is empty?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To check whether the first argument is empty or not use the operators such <strong>-n<\/strong> or <strong>-z<\/strong> with the <strong>test<\/strong> command in an if statement. <code class=\"\" data-line=\"\">if [ -n &quot;$1&quot; ]<\/code> holds true if the length of the first argument is nonzero. On the other hand,\u00a0 <code class=\"\" data-line=\"\">if [ -z &quot;$1&quot; ]<\/code> is true if the length of the first argument is 0.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_the_difference_between_1_and\"><\/span>What is the difference between $1 and $@?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Though both $1 and $@ are used to represent command line arguments, they don\u2019t refer to the same set of arguments. $1 is used to access the first positional parameter whereas $@ expands to all the command line arguments. One can say, &#8220;$@&#8221; is equivalent to &#8220;$1&#8221; &#8220;$2&#8221; &#8220;$3&#8243;&#8230;up to the last argument.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_store_the_first_argument_in_a_variable_in_Bash_script\"><\/span>How to store the first argument in a variable in Bash script?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Assign $1 as the value of a variable to store the first argument in a variable within a Bash script. For instance:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Store the first argument in a variable\narg1=$1<\/code><\/pre>\n<p style=\"text-align: justify;\">Here, variable <strong>arg1<\/strong> contains the value of the first argument provided to the script.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Why_is_1_in_a_function_not_printing_the_scripts_first_argument\"><\/span>Why is $1 in a function not printing the script&#8217;s first argument?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">$1 in a function can\u2019t print a script\u2019s first argument. Arguments provided to a script are accessible using positional parameters only within the main level of the script not in a function body written in the script. A function can take its own set of arguments independent of the parent script containing the function. So, a function written in a script can access arguments that are provided to the function while calling the function within the script.<\/p>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"How to check if the first argument is empty?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To check whether the first argument is empty or not use the operators such -n or -z with the test command in an if statement. if [ -n \\\"$1\\\" ] holds true if the length of the first argument is nonzero. On the other hand,\u00a0 if [ -z \\\"$1\\\" ] is true if the length of the first argument is 0.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What is the difference between $1 and $@?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Though both $1 and $@ are used to represent command line arguments, they don\u2019t refer to the same set of arguments. $1 is used to access the first positional parameter whereas $@ expands to all the command line arguments. One can say, \\\"$@\\\" is equivalent to \\\"$1\\\" \\\"$2\\\" \\\"$3\\\"...up to the last argument.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"How to store the first argument in a variable in Bash script?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Assign $1 as the value of a variable to store the first argument in a variable within a Bash script. For instance:<\/p>\n<p>#!\/bin\/bash<\/p>\n<p># Store the first argument in a variable\narg1=$1<\/p>\n<p>Here, variable arg1 contains the value of the first argument provided to the script.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Why is $1 in a function not printing the script's first argument?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"$1 in a function can\u2019t print a script\u2019s first argument. Arguments provided to a script are accessible using positional parameters only within the main level of the script not in a function body written in the script. A function can take its own set of arguments independent of the parent script containing the function. So, a function written in a script can access arguments that are provided to the function while calling the function within the script.\"\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\/functions\/script-argument\/number-of-args\/\" target=\"_blank\" rel=\"noopener\">How to Check Number of Arguments in Bash? [3 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/get-argument\/\" target=\"_blank\" rel=\"noopener\">How to Get Argument in Bash? [4 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/pass-arguments\/\" target=\"_blank\" rel=\"noopener\">How to Pass Arguments to Bash Script? [5 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/optional-arguments\/\" target=\"_blank\" rel=\"noopener\">How to Parse Optional Arguments in Bash Script [2 Ways]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/pass-array-to-function\/\" target=\"_blank\" rel=\"noopener\">How to Pass Array as an Argument in Bash Function? [3 Ways]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/default-argument\/\" target=\"_blank\" rel=\"noopener\">How to Set Default Argument in Bash [2 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/bash-optarg\/\" target=\"_blank\" rel=\"noopener\">How to Use OPTARG in Bash [3 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/bash-getopts\/\" target=\"_blank\" rel=\"noopener\">How to Use \u201cgetopts\u201d in Bash [Complete Guide]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/argument-list-too-long\/\" target=\"_blank\" rel=\"noopener\">[Solved] \u201cbash: Argument list too long\u201d Error<\/a><\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>&lt;&lt; Go Back to <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Argument in Bash Script&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/\" target=\"_blank\" rel=\"noopener\">Argument in Bash Script<\/a><\/span> | <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Functions&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/\" target=\"_blank\" rel=\"noopener\">Bash Functions<\/a><\/span> | <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Scripting Tutorial&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Tutorial<\/a><\/span><\/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;37848&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;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&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;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;How to Use First Argument in Bash Script [5 Cases]&quot;,&quot;width&quot;:&quot;0&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: 0px;\">\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            <span class=\"kksr-muted\">Rate this post<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>In Bash, $1 represents the first argument of a script. This means when users provide the first argument while executing &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Use First Argument in Bash Script [5 Cases]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#more-37848\" aria-label=\"Read more about How to Use First Argument in Bash Script [5 Cases]\">Read more<\/a><\/p>\n","protected":false},"author":314903,"featured_media":37855,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[202],"class_list":["post-37848","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-bash-script-argument","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 First Argument in Bash Script [5 Cases] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"Parsing and accessing the first argument in Bash is important. This article talks about how to do this as well as a few cases of handling the first argument.\" \/>\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\/functions\/script-argument\/first-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 First Argument in Bash Script [5 Cases] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"Parsing and accessing the first argument in Bash is important. This article talks about how to do this as well as a few cases of handling the first argument.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/zahidlaku72\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-28T02:57:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-23T03:57:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-first-argument.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=\"Md Zahidul Islam Laku\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Md Zahidul Islam Laku\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 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\\\/functions\\\/script-argument\\\/first-argument\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-argument\\\/\"},\"author\":{\"name\":\"Md Zahidul Islam Laku\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/26b37b2c7517d2c8702472bc3986ef21\"},\"headline\":\"How to Use First Argument in Bash Script [5 Cases]\",\"datePublished\":\"2024-02-28T02:57:45+00:00\",\"dateModified\":\"2024-04-23T03:57:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-argument\\\/\"},\"wordCount\":1535,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-argument\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/bash-first-argument.png\",\"keywords\":[\"bash script argument\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-argument\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-argument\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-argument\\\/\",\"name\":\"How to Use First Argument in Bash Script [5 Cases] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-argument\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-argument\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/bash-first-argument.png\",\"datePublished\":\"2024-02-28T02:57:45+00:00\",\"dateModified\":\"2024-04-23T03:57:34+00:00\",\"description\":\"Parsing and accessing the first argument in Bash is important. This article talks about how to do this as well as a few cases of handling the first argument.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-argument\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-argument\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-argument\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/bash-first-argument.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/bash-first-argument.png\",\"width\":400,\"height\":400,\"caption\":\"bash first argument\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/first-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 Functions\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Argument in Bash Script\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/script-argument\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to Use First Argument in Bash Script [5 Cases]\"}]},{\"@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\\\/26b37b2c7517d2c8702472bc3986ef21\",\"name\":\"Md Zahidul Islam Laku\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"caption\":\"Md Zahidul Islam Laku\"},\"description\":\"Hey, I'm Zahidul Islam Laku currently working as a Linux Content Developer Executive at SOFTEKO. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). I write articles on a variety of tech topics including Linux. Learning and writing on Linux is nothing but fun as it gives me more power on my machine. What can be more efficient than interacting with the Operating System without Graphical User Interface! Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/zahidlaku72\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/zahidlaku\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCnxMIaAb-nXO5XnMeEaNhpQ\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/laku\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Use First Argument in Bash Script [5 Cases] - LinuxSimply","description":"Parsing and accessing the first argument in Bash is important. This article talks about how to do this as well as a few cases of handling the first argument.","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\/functions\/script-argument\/first-argument\/","og_locale":"en_US","og_type":"article","og_title":"How to Use First Argument in Bash Script [5 Cases] - LinuxSimply","og_description":"Parsing and accessing the first argument in Bash is important. This article talks about how to do this as well as a few cases of handling the first argument.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/zahidlaku72","article_published_time":"2024-02-28T02:57:45+00:00","article_modified_time":"2024-04-23T03:57:34+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-first-argument.png","type":"image\/png"}],"author":"Md Zahidul Islam Laku","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Md Zahidul Islam Laku","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/"},"author":{"name":"Md Zahidul Islam Laku","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/26b37b2c7517d2c8702472bc3986ef21"},"headline":"How to Use First Argument in Bash Script [5 Cases]","datePublished":"2024-02-28T02:57:45+00:00","dateModified":"2024-04-23T03:57:34+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/"},"wordCount":1535,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-first-argument.png","keywords":["bash script argument"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/","name":"How to Use First Argument in Bash Script [5 Cases] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-first-argument.png","datePublished":"2024-02-28T02:57:45+00:00","dateModified":"2024-04-23T03:57:34+00:00","description":"Parsing and accessing the first argument in Bash is important. This article talks about how to do this as well as a few cases of handling the first argument.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-argument\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-first-argument.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-first-argument.png","width":400,"height":400,"caption":"bash first argument"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/first-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 Functions","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/"},{"@type":"ListItem","position":4,"name":"Argument in Bash Script","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/"},{"@type":"ListItem","position":5,"name":"How to Use First Argument in Bash Script [5 Cases]"}]},{"@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\/26b37b2c7517d2c8702472bc3986ef21","name":"Md Zahidul Islam Laku","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","caption":"Md Zahidul Islam Laku"},"description":"Hey, I'm Zahidul Islam Laku currently working as a Linux Content Developer Executive at SOFTEKO. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). I write articles on a variety of tech topics including Linux. Learning and writing on Linux is nothing but fun as it gives me more power on my machine. What can be more efficient than interacting with the Operating System without Graphical User Interface! Read Full Bio","sameAs":["https:\/\/www.facebook.com\/zahidlaku72","https:\/\/www.linkedin.com\/in\/zahidlaku\/","https:\/\/www.youtube.com\/channel\/UCnxMIaAb-nXO5XnMeEaNhpQ"],"url":"https:\/\/linuxsimply.com\/author\/laku\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/37848","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\/314903"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=37848"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/37848\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/37855"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=37848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=37848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=37848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}