{"id":18029,"date":"2023-08-29T07:37:42","date_gmt":"2023-08-29T07:37:42","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=18029"},"modified":"2023-11-27T03:07:33","modified_gmt":"2023-11-27T03:07:33","slug":"0-bash","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/","title":{"rendered":"What is &#8220;$0&#8221; in Bash Script? [4 Practical Examples]"},"content":{"rendered":"<p style=\"text-align: justify;\">In bash scripting, <strong>$0<\/strong> is a <strong>special parameter<\/strong>. It represents the <strong>name of the script <\/strong>or the <strong>currently executing shell script<\/strong>. When you run a bash script, <strong>$0<\/strong> holds the name of the script file itself. This variable can be useful for self-referencing within the script or for displaying the <strong>script&#8217;s name <\/strong>in messages or logs. In this article, I am going to show you 4 different examples by<strong> using $0 in bash script<\/strong>. So let\u2019s start.<\/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' ><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#Key_Takeaways\" >Key Takeaways<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#Free_Downloads\" >Free Downloads<\/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\/parameters\/dollar-0\/#Meaning_Purpose_of_%E2%80%9C0%E2%80%9D_in_Bash_Scripting\" >Meaning &amp; Purpose of &#8220;$0&#8221; in Bash Scripting<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#4_Practical_Examples_of_Using_%E2%80%9C0%E2%80%9D_Parameter_in_Bash_Script\" >4 Practical Examples of Using &#8220;$0&#8221; Parameter 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-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#Example_01_Displaying_the_Current_Shell_Script_Name_by_Using_the_%E2%80%9C0%E2%80%9D_Parameter\" >Example 01: Displaying the Current Shell Script Name by Using the &#8220;$0&#8221; Parameter<\/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\/parameters\/dollar-0\/#Example_02_Displaying_Script_Location_Using_%E2%80%9C0%E2%80%9D_Parameter\" >Example 02: Displaying Script Location Using &#8220;$0&#8221; Parameter<\/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\/parameters\/dollar-0\/#Example_03_Read_a_File_Using_%E2%80%9C0%E2%80%9D_Parameter_in_Bash_Script\" >Example 03: Read a File Using &#8220;$0&#8221; Parameter 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\/parameters\/dollar-0\/#Example_04_Using_the_%E2%80%9C0%E2%80%9D_Parameter_in_the_Bash_Function\" >Example 04: Using the &#8220;$0&#8221; Parameter in the Bash Function<\/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\/parameters\/dollar-0\/#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\/parameters\/dollar-0\/#People_Also_Ask\" >People Also Ask<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Key_Takeaways\"><\/span>Key Takeaways<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Learning about the $0 special parameter and its usability in a bash script.<\/li>\n<li>Retrieving the path directory of the file using the $0 parameter.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Free_Downloads\"><\/span>Free Downloads<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/Practice_files_0-bash.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> Download the Practice Files<\/span><\/a><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Meaning_Purpose_of_%E2%80%9C0%E2%80%9D_in_Bash_Scripting\"><\/span>Meaning &amp; Purpose of &#8220;$0&#8221; in Bash Scripting<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <strong>special variable<\/strong> <strong>$0<\/strong> in the bash code represents the name of the currently executed script or shell. This variable is particularly useful for self-referencing within scripts, allowing you to access the <strong>script&#8217;s name<\/strong> to create dynamic behavior. For instance, you might use it to display the<strong> script&#8217;s name<\/strong> in error messages or to derive the <strong>script&#8217;s directory path<\/strong>. By referencing <strong>$0<\/strong>, you can make your script more adaptable and informative.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"4_Practical_Examples_of_Using_%E2%80%9C0%E2%80%9D_Parameter_in_Bash_Script\"><\/span>4 Practical Examples of Using &#8220;$0&#8221; Parameter in Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">As I have said earlier, you can <strong>retrieve <\/strong>the <strong>script name <\/strong>or <strong>path location <\/strong>by using the <strong>$0 parameter<\/strong>. To give you a hands-on experience, I am going to discuss<strong> 4<\/strong> different <strong>examples<\/strong> of using<strong> $0 <\/strong>in a bash script. Let\u2019s check these out.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_01_Displaying_the_Current_Shell_Script_Name_by_Using_the_%E2%80%9C0%E2%80%9D_Parameter\"><\/span>Example 01: Displaying the Current Shell Script Name by Using the &#8220;$0&#8221; Parameter<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In bash scripting, you can utilize the<strong> $0 parameter<\/strong> to display the <strong>name of the currently running shell script<\/strong>. To display the <strong>script&#8217;s name<\/strong>, you can simply use the<strong> $0 parameter<\/strong> within your script, like this:<\/p>\n<p><span style=\"color: #800080;\"><strong><a id=\"an\"><\/a>Steps to Follow &gt;<\/strong><\/span><\/p>\n<p>\u2776 At first, launch an <strong>Ubuntu <\/strong><a href=\"https:\/\/linuxsimply.com\/what-is-terminal-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>Terminal<\/strong><\/a>.<\/p>\n<p>\u2777 Write the following command to open a file in Nano:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">nano LinuxSimply.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><strong>:<\/strong> Opens a file in the Nano text editor.<\/li>\n<li><strong>LinuxSimply.sh<\/strong>: Name of the file.<\/li>\n<\/ul>\n<\/div><\/div>\n<p>\u2778 Copy the script mentioned below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Display the script name\necho &quot;The name of the current shell script is: $0&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 Bash script begins with a <strong>shebang <\/strong>(<strong>#!\/bin\/bash<\/strong>) indicating that it should be <strong>interpreted <\/strong>and <strong>executed <\/strong>using the Bash shell. The <a href=\"https:\/\/linuxsimply.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a> is used to print the text &#8220;<strong>The name of the current shell script is:<\/strong> &#8221; followed by the value of the special variable <strong>$0<\/strong>, which represents the <strong>name of the script <\/strong>itself. When the script is executed, it will output the name of the script to the terminal.<\/p>\n<\/div><\/div>\n<p>\u2779 Press<strong> CTRL+O<\/strong> and <strong>ENTER <\/strong>to save the file;<strong> CTRL+X <\/strong>to exit.<\/p>\n<p>\u277a Use the following command to make the file executable:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">chmod u+x LinuxSimply.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 the permissions of files and directories.<\/li>\n<li><strong>u+x<\/strong>: Here, <strong>u<\/strong> refers to the &#8220;<strong>user<\/strong>&#8221; or the <strong>owner <\/strong>of the file and <strong>+x<\/strong> specifies the permission being added, in this case, the &#8220;<strong>execute<\/strong>&#8221; permission. When <strong>u+x<\/strong> is added to the file permissions, it grants the user (<strong>owner<\/strong>) permission to execute (<strong>run<\/strong>) the file.<\/li>\n<li><strong>LinuxSimply.sh <\/strong>: File name.<\/li>\n<\/ul>\n<\/div><\/div>\n<p>\u277b Run the script by the following command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/LinuxSimply.sh<\/code><\/pre>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-18031 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/1.-Displaying-the-Current-Shell-Script-Name-by-Using-the-0-Parameter.png\" alt=\"Displaying the Current Shell Script Name by Using the $0 Parameter\" width=\"654\" height=\"142\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/1.-Displaying-the-Current-Shell-Script-Name-by-Using-the-0-Parameter.png 654w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/1.-Displaying-the-Current-Shell-Script-Name-by-Using-the-0-Parameter-300x65.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/1.-Displaying-the-Current-Shell-Script-Name-by-Using-the-0-Parameter-765x166.png 765w\" sizes=\"(max-width: 654px) 100vw, 654px\" \/>As the image shows, the code returns &#8220;<strong>The name of the current shell script is:<\/strong> <strong>.\/LinuxSimply.sh <\/strong>in the command line.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_02_Displaying_Script_Location_Using_%E2%80%9C0%E2%80%9D_Parameter\"><\/span>Example 02: Displaying Script Location Using &#8220;$0&#8221; Parameter<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Following the previous example, I am going to provide another bash code by using the <strong>$0 parameter<\/strong>. The script&#8217;s purpose is to determine and display the <strong>directory containing <\/strong>the <strong>script <\/strong>itself. When the script is executed, it will output the <a href=\"https:\/\/linuxsimply.com\/absolute-path-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>absolute path<\/strong><\/a> to the directory containing the script.<\/p>\n<div class=\"su-note\"  style=\"border-color:#e5e5e5;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#ffffff;border-color:#ffffff;color:#333333;\">\n<p>You can follow the <a href=\"#an\"><strong>steps of Example 01<\/strong><\/a>, to save &amp; make the script executable.<\/p>\n<\/div><\/div>\n<p><span style=\"color: #800080;\"><strong>Script (file_location.sh) &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Get the directory containing the script using readlink\nscript_directory=$(dirname &quot;$(readlink -f &quot;$0&quot;)&quot;)\n\n# Print the script location\necho &quot;Script location: $script_directory&quot; \n<\/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>First, the <strong>readlink -f &#8220;$0&#8221;<\/strong> <strong>command <\/strong>retrieves the <strong>absolute path <\/strong>of the script, and the <strong>dirname command <\/strong>extracts the directory from the obtained path. The result is stored in the variable <strong>script_directory<\/strong>. The <strong>echo command <\/strong>prints the message &#8220;<strong>Script location:<\/strong> &#8221; followed by the value stored in <strong>script_directory<\/strong>.<\/p>\n<\/div><\/div>\n<p>Run the following command in your terminal.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/file_location.sh<\/code><\/pre>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter wp-image-18032 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/2.-Displaying-Script-Location-Using-0-Parameter.png\" alt=\"Displaying Script Location Using $0 Parameter\" width=\"643\" height=\"123\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/2.-Displaying-Script-Location-Using-0-Parameter.png 643w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/2.-Displaying-Script-Location-Using-0-Parameter-300x57.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/2.-Displaying-Script-Location-Using-0-Parameter-763x146.png 763w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/>As the image shows above, the command line returns<strong> Script location: \/home\/miran <\/strong>as the absolute directory of the current shell script.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_03_Read_a_File_Using_%E2%80%9C0%E2%80%9D_Parameter_in_Bash_Script\"><\/span>Example 03: Read a File Using &#8220;$0&#8221; Parameter in Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Apart from displaying the <strong>file name<\/strong>, we can also<strong> read <\/strong>the content of the file using the<strong> $0<\/strong> <strong>parameter <\/strong>in the bash script. Here, I am going to give another bash script. The script&#8217;s purpose is to <strong>read <\/strong>and <strong>process <\/strong>each line from a file named &#8220;<strong>filename.txt<\/strong>&#8221; located in the same directory as the script. In <strong>filename.txt<\/strong>, it contains <strong>Hello LinuxSimply<\/strong> in it. Now I will read this content with the help of a bash code. So let\u2019s see.<\/p>\n<div class=\"su-note\"  style=\"border-color:#e5e5e5;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#ffffff;border-color:#ffffff;color:#333333;\">\n<p>You can follow the <a href=\"#an\"><strong>steps of Example 01<\/strong><\/a>, to save &amp; make the script executable.<\/p>\n<\/div><\/div>\n<p><span style=\"color: #800080;\"><strong>Script (read_file.sh) &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Extract the directory path of the script\nscript_dir=$(dirname &quot;$0&quot;)\n\n# Define the file path relative to the script directory\nfile_path=&quot;$script_dir\/filename.txt&quot;\n\n# Read and process each line from the file\nwhile IFS= read -r line; do\n    echo &quot;Line: $line&quot;\ndone &lt; &quot;$file_path\n<\/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 starts by using the <strong>dirname <\/strong>&#8220;<strong>$0<\/strong>&#8221; <strong>command <\/strong>to extract the directory path of the script itself and <strong>stores <\/strong>it in the variable <strong>script_dir<\/strong>. Then, the <strong>file_path <\/strong>variable is defined by concatenating <strong>script_dir <\/strong>with &#8220;<strong>\/filename.txt<\/strong>&#8220;.<\/p>\n<p>The script enters a <strong>while loop <\/strong>that reads each line from the file specified by <strong>$file_path<\/strong>. The <strong>IFS= read -r <\/strong>line command reads each line while preserving <strong>leading <\/strong>and <strong>trailing <\/strong>whitespace. The loop continues until all lines have been read from the file. The <strong>&lt; &#8220;$file_path&#8221;<\/strong> at the end of the loop ensures that the loop&#8217;s input comes from the specified file. When executed, the script will <strong>read filename.txt<\/strong> line by line and <strong>display <\/strong>each line along with the &#8220;<strong>Line: <\/strong>&#8221; prefix.<\/p>\n<\/div><\/div>\n<p>Execute the following command in your terminal.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/read_file.sh<\/code><\/pre>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter wp-image-18033 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Read-a-File-Using-0-Parameter-in-Bash-Script.png\" alt=\"Read a File Using $0 Parameter in Bash Script\" width=\"583\" height=\"111\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Read-a-File-Using-0-Parameter-in-Bash-Script.png 583w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Read-a-File-Using-0-Parameter-in-Bash-Script-300x57.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/3.-Read-a-File-Using-0-Parameter-in-Bash-Script-767x146.png 767w\" sizes=\"(max-width: 583px) 100vw, 583px\" \/>As you can see, the command line returns <strong>Line: Hello LinuxSimply<\/strong> as data contained in the <strong>filename.txt<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_04_Using_the_%E2%80%9C0%E2%80%9D_Parameter_in_the_Bash_Function\"><\/span>Example 04: Using the &#8220;$0&#8221; Parameter in the Bash Function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can also incorporate the <strong>$0 parameter in a bash function<\/strong>. Here I am going to provide a sample bash code to illustrate the idea. The purpose of this <strong>Bash script <\/strong>is to define a function called <strong>func<\/strong> that takes <strong>two parameters<\/strong>, <strong>calculates <\/strong>their <strong>multiplication<\/strong>, and then <strong>displays <\/strong>the <strong>result <\/strong>along with the <strong>name of the script<\/strong>.<\/p>\n<div class=\"su-note\"  style=\"border-color:#e5e5e5;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#ffffff;border-color:#ffffff;color:#333333;\">\n<p>You can follow the <a href=\"#an\"><strong>steps of Example 01<\/strong><\/a>, to save &amp; make the script executable.<\/p>\n<\/div><\/div>\n<p><span style=\"color: #800080;\"><strong>Script (bash_function.sh) &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nfunc() {\n    Mul=$(( $1 * $2 ))\n    echo &quot;The multiplication of the two given numbers is: $Mul&quot;\n    echo &quot;The name of the script is:&quot; $0\n}\nfunc $1 $2\n<\/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 <strong>Bash script <\/strong>begins with a <strong>shebang <\/strong>(<strong>#!\/bin\/bash<\/strong>) indicating it&#8217;s executed using <strong>Bash<\/strong>. It defines a function <strong>func <\/strong>that takes <strong>two parameters<\/strong>. Inside the <strong>function<\/strong>, the parameters are <strong>multiplied <\/strong>and <strong>stored <\/strong>in the variable <strong>Mul<\/strong>. The script then <strong>echoes <\/strong>the <strong>multiplication <\/strong>result <strong>and <\/strong>the <strong>script&#8217;s name <\/strong>using the <strong>special variable $0<\/strong>. Finally, the function is invoked with the provided arguments from the command line (<strong>$1 <\/strong>and<strong> $2<\/strong>).<\/p>\n<\/div><\/div>\n<p>Use the following command to run the script.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/$0_function.sh 4 3<\/code><\/pre>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-18034 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/4.-Using-the-0-Parameter-in-the-Bash-Function.png\" alt=\"Using the $0 Parameter in the Bash Function\" width=\"700\" height=\"162\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/4.-Using-the-0-Parameter-in-the-Bash-Function.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/4.-Using-the-0-Parameter-in-the-Bash-Function-300x69.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/4.-Using-the-0-Parameter-in-the-Bash-Function-765x177.png 765w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>As the image depicts above, I passed 4 and 3 integers along with the script name. Then, the script returns <strong>The multiplication of the two given numbers is: 12 <\/strong>and <strong>The name of the script is: .\/bash_function.sh <\/strong>as 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 conclusion, the<strong> $0<\/strong> <strong>parameter <\/strong>in bash scripting serves as a valuable tool for <strong>referencing the name<\/strong> of the <strong>currently executing script or shell<\/strong>. By incorporating <strong>$0 <\/strong>into your script, you can easily retrieve and utilize the <strong>script&#8217;s name, handle errors <\/strong>etc. In this article, I have provided 4 different examples to illustrate the idea fully. However, If you have any questions or queries, don\u2019t forget to comment below. Thank You!<\/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<div class=\"su-accordion su-u-trim\">\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>What is $0 and $1 in shell script?<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"> In a shell script, <strong>$0<\/strong> represents the <strong>script&#8217;s name <\/strong>or path, and <strong>$1 <\/strong>represents the <strong>first argument <\/strong>passed when running the script or function. <\/div><\/div>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>What does bash $[ 0 \/*] mean?<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"> <strong>${0\/*}<\/strong> extracts the filename from the <strong>$0 parameter<\/strong>, effectively <strong>removing the path information<\/strong>. It helps isolate the script&#8217;s name from its location. <\/div><\/div>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>What is the difference between $0 and $shell?<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"> <strong>$0<\/strong> refers to the <strong>name or path <\/strong>of the script or shell being executed, while <strong>$SHELL <\/strong>represents the <strong>user&#8217;s default shell <\/strong>as defined in their system settings. <\/div><\/div>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>What is 0&gt; and 1 bash?<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n<p><strong>0 &gt;<\/strong> &amp; <strong>1<\/strong> in <strong>Linux <\/strong>is used to <strong>redirect the standard input <\/strong>(file descriptor <strong>0<\/strong>) to the same location as the <strong>standard output <\/strong>(file descriptor <strong>1<\/strong>). This essentially means that the <strong>input <\/strong>and <strong>output <\/strong>streams are <strong>merged<\/strong>, so whatever is normally shown on the screen or terminal will also be used as input.<\/p>\n<\/div><\/div>\n<\/div>\n<p><strong><span style=\"font-size: 18pt; color: #003366;\">Related Articles<\/span><\/strong><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/all-bash-parameters\/\" target=\"_blank\" rel=\"noopener\">How to Pass All Parameters in Bash Scripts? [6 Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/positional-parameters\/\" target=\"_blank\" rel=\"noopener\">How to Use Positional Parameters in Bash Script? [2 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/parsing\/\" target=\"_blank\" rel=\"noopener\">Parsing Parameters in Bash Scripts [5 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/named-parameters\/\" target=\"_blank\" rel=\"noopener\">4 Methods to Pass Named Parameters in a Bash Script<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/double-vs-single-dollar\/\" target=\"_blank\" rel=\"noopener\">Difference Between $$ Vs $ in Bash Scripting [With Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/alias-parameters\/\" target=\"_blank\" rel=\"noopener\">How to Use Alias with Parameters in Bash Scripting? [6 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/function-parameters\/\" target=\"_blank\" rel=\"noopener\">How to Use Bash Function with Parameters? [6 Examples]<\/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;Parameters in Bash Scripting&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\/parameters\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/\" target=\"_blank\" rel=\"noopener\">Parameters in Bash Scripting<\/a><\/span> | <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Scripting Tutorial&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\/\"><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;18029&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;8&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&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;5\\\/5 - (8 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;What is \\u0026quot;$0\\u0026quot; in Bash Script? [4 Practical Examples]&quot;,&quot;width&quot;:&quot;142.5&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: 142.5px;\">\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            5\/5 - (8 votes)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>In bash scripting, $0 is a special parameter. It represents the name of the script or the currently executing shell &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"What is &#8220;$0&#8221; in Bash Script? [4 Practical Examples]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#more-18029\" aria-label=\"Read more about What is &#8220;$0&#8221; in Bash Script? [4 Practical Examples]\">Read more<\/a><\/p>\n","protected":false},"author":314906,"featured_media":18035,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[131],"class_list":["post-18029","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-bash-paramters","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>What is &quot;$0&quot; in Bash Script? [4 Practical Examples] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"The special parameter $0 in Bash holds the script&#039;s name. It aids in referencing the script&#039;s name within the code for various purposes.\" \/>\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\/parameters\/dollar-0\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is &quot;$0&quot; in Bash Script? [4 Practical Examples] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"The special parameter $0 in Bash holds the script&#039;s name. It aids in referencing the script&#039;s name within the code for various purposes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/msmshah.miran\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-29T07:37:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-27T03:07:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/0-bash.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=\"Mohammad Shah Miran\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mohammad Shah Miran\" \/>\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\\\/parameters\\\/dollar-0\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/\"},\"author\":{\"name\":\"Mohammad Shah Miran\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/3d367dace727c53f2b8683eeb23fae77\"},\"headline\":\"What is &#8220;$0&#8221; in Bash Script? [4 Practical Examples]\",\"datePublished\":\"2023-08-29T07:37:42+00:00\",\"dateModified\":\"2023-11-27T03:07:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/\"},\"wordCount\":1582,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/0-bash.png\",\"keywords\":[\"bash paramters\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/\",\"name\":\"What is \\\"$0\\\" in Bash Script? [4 Practical Examples] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/0-bash.png\",\"datePublished\":\"2023-08-29T07:37:42+00:00\",\"dateModified\":\"2023-11-27T03:07:33+00:00\",\"description\":\"The special parameter $0 in Bash holds the script's name. It aids in referencing the script's name within the code for various purposes.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/0-bash.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/0-bash.png\",\"width\":400,\"height\":400,\"caption\":\"$0 bash\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/dollar-0\\\/#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\":\"Parameters in Bash Scripting\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/parameters\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"What is &#8220;$0&#8221; in Bash Script? [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\\\/3d367dace727c53f2b8683eeb23fae77\",\"name\":\"Mohammad Shah Miran\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"caption\":\"Mohammad Shah Miran\"},\"description\":\"Hey, I'm Mohammad Shah Miran, previously worked as a VBA and Excel Content Developer at SOFTEKO, and for now working as a Linux Content Developer Executive in LinuxSimply Project. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). As a part of my job, i communicate with Linux operating system, without letting the GUI to intervene and try to pass it to our audience.\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/msmshah.miran\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/shah-miran-2a94a7144\\\/\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/miran\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is \"$0\" in Bash Script? [4 Practical Examples] - LinuxSimply","description":"The special parameter $0 in Bash holds the script's name. It aids in referencing the script's name within the code for various purposes.","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\/parameters\/dollar-0\/","og_locale":"en_US","og_type":"article","og_title":"What is \"$0\" in Bash Script? [4 Practical Examples] - LinuxSimply","og_description":"The special parameter $0 in Bash holds the script's name. It aids in referencing the script's name within the code for various purposes.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/msmshah.miran\/","article_published_time":"2023-08-29T07:37:42+00:00","article_modified_time":"2023-11-27T03:07:33+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/0-bash.png","type":"image\/png"}],"author":"Mohammad Shah Miran","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mohammad Shah Miran","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/"},"author":{"name":"Mohammad Shah Miran","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/3d367dace727c53f2b8683eeb23fae77"},"headline":"What is &#8220;$0&#8221; in Bash Script? [4 Practical Examples]","datePublished":"2023-08-29T07:37:42+00:00","dateModified":"2023-11-27T03:07:33+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/"},"wordCount":1582,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/0-bash.png","keywords":["bash paramters"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/","name":"What is \"$0\" in Bash Script? [4 Practical Examples] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/0-bash.png","datePublished":"2023-08-29T07:37:42+00:00","dateModified":"2023-11-27T03:07:33+00:00","description":"The special parameter $0 in Bash holds the script's name. It aids in referencing the script's name within the code for various purposes.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/0-bash.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/08\/0-bash.png","width":400,"height":400,"caption":"$0 bash"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/dollar-0\/#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":"Parameters in Bash Scripting","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/"},{"@type":"ListItem","position":4,"name":"What is &#8220;$0&#8221; in Bash Script? [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\/3d367dace727c53f2b8683eeb23fae77","name":"Mohammad Shah Miran","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","caption":"Mohammad Shah Miran"},"description":"Hey, I'm Mohammad Shah Miran, previously worked as a VBA and Excel Content Developer at SOFTEKO, and for now working as a Linux Content Developer Executive in LinuxSimply Project. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). As a part of my job, i communicate with Linux operating system, without letting the GUI to intervene and try to pass it to our audience.","sameAs":["https:\/\/www.facebook.com\/msmshah.miran\/","https:\/\/www.linkedin.com\/in\/shah-miran-2a94a7144\/"],"url":"https:\/\/linuxsimply.com\/author\/miran\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/18029","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\/314906"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=18029"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/18029\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/18035"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=18029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=18029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=18029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}