{"id":14430,"date":"2023-07-31T04:44:16","date_gmt":"2023-07-31T04:44:16","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=14430"},"modified":"2024-01-23T05:41:48","modified_gmt":"2024-01-23T05:41:48","slug":"writing-bash-script","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/","title":{"rendered":"Writing Bash Script"},"content":{"rendered":"<p style=\"text-align: justify;\">Bash scripting is a powerful tool that allows you to <strong>automate tasks<\/strong>, <strong>streamline processes<\/strong>, and enhance your productivity as a developer or system administrator. Understanding the fundamentals of <strong>writing Bash scripts<\/strong> is essential for anyone seeking to harness the full potential of the <a href=\"https:\/\/linuxsimply.com\/cli-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>command line interface<\/strong><\/a>. This article will explore the basics of <strong>writing Bash scripts<\/strong>, covering important concepts such as the Bash symbol, shebang, script commands, and chaining multiple commands.<\/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\/basics\/writing\/#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\/basics\/writing\/#Download_File\" >Download File<\/a><\/li><\/ul><\/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\/basics\/writing\/#Step-by-Step_Guide_to_Write_a_Bash_Script\" >Step-by-Step Guide to Write a 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\/basics\/writing\/#1_Getting_Started_Initiating_a_Bash_Script\" >1. Getting Started: Initiating a Bash Script<\/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\/basics\/writing\/#2_The_Shebang_Line_binbash\" >2. The Shebang Line: #!\/bin\/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\/basics\/writing\/#3_Bash_Script_Commands\" >3. Bash Script Commands<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#Some_Practical_Examples_of_Writing_a_Bash_Script\" >Some Practical Examples of Writing a 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-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#Example_01_Printing_a_Greetings_on_the_Terminal\" >Example 01: Printing a Greetings on the Terminal<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#Example_02_Taking_Input_From_the_User_Then_Print_It\" >Example 02: Taking Input From the User Then Print It<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#Example_03_Performing_Arithmetic_Operations_by_Taking_Two_Input_Numbers_from_the_User\" >Example 03: Performing Arithmetic Operations by Taking Two Input Numbers from the User<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#Example_04_Using_a_Function_in_the_Bash_Script\" >Example 04: Using a Function in the 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-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#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>Getting familiar with the process of writing Bash script.<\/li>\n<li>Getting familiar with the utilities of Bash script.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Download_File\"><\/span><strong>Download File<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\"><div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/writing-bash-script.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><\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step-by-Step_Guide_to_Write_a_Bash_Script\"><\/span>Step-by-Step Guide to Write a Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>While programmers write Bash script, they follow some steps sequentially. Here, I have discussed these steps briefly.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Getting_Started_Initiating_a_Bash_Script\"><\/span>1. Getting Started: Initiating a Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To begin writing a Bash script, open a text editor and create a new file with the &#8220;<strong>.sh&#8221;<\/strong> extension. This extension is commonly used to indicate that the file contains a Bash script. At the start of your script, it is important to include the &#8220;<strong>shebang&#8221;<\/strong>\u00a0line.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_The_Shebang_Line_binbash\"><\/span>2. The Shebang Line: #!\/bin\/bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The shebang line, also known as the shebang or the <strong>interpreter directive<\/strong>, informs the system which interpreter should be used to execute the script. In the case of the Bash script, the shebang line is &#8220;<strong>#!\/bin\/bash&#8221;<\/strong>. This line should always be the first line of your script.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Bash_Script_Commands\"><\/span>3. Bash Script Commands<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Bash script allows you to execute commands and perform various operations. Examples of commonly used Bash Script commands are <strong>echo<\/strong>, <strong>read<\/strong>, <strong>if<\/strong>, <strong>else<\/strong>, and <strong>elif<\/strong>. There are some special symbols for <strong>chaining commands<\/strong> which help the programmer execute <strong>multiple commands<\/strong> in a single line.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Some_Practical_Examples_of_Writing_a_Bash_Script\"><\/span>Some Practical Examples of Writing a Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In this section, I have demonstrated some sample Bash scripts that will help you to understand the basic concept of a Bash script.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_01_Printing_a_Greetings_on_the_Terminal\"><\/span>Example 01: Printing a Greetings on the Terminal<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Here I will develop a Bash script that will print a greeting on the <strong>terminal<\/strong>. To do so, follow the below procedures.<\/p>\n<p><span style=\"color: #800080;\"><strong><a id=\"steps_of_example_01\"><\/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 sample.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 the nano text editor.<\/li>\n<li><strong>sample.sh:<\/strong> Bash script name.<\/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\necho&quot;Happy Scripting&quot; #prints the greetings on the terminal<\/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>#!\/bin\/bash<\/strong> interprets that it is a Bash script. Then the <strong><a href=\"https:\/\/linuxsimply.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">echo command<\/a><\/strong> prints greetings on 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>\u277b Run the script by the following command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">bash sample.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><strong>bash<\/strong><strong>: <\/strong>Executes the bash scripts.<\/li>\n<li><strong>sample.sh:<\/strong> Bash script name.<\/li>\n<\/ul>\n<\/div><\/div>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-14432 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/1-sample-script.png\" alt=\"A Bash script written which prints a greetings on the terminal.\" width=\"646\" height=\"159\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/1-sample-script.png 646w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/1-sample-script-300x74.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/1-sample-script-768x189.png 768w\" sizes=\"(max-width: 646px) 100vw, 646px\" \/>The above image shows that Bash script has printed a greeting text on the terminal.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_02_Taking_Input_From_the_User_Then_Print_It\"><\/span>Example 02: Taking Input From the User Then Print It<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can take input from the user while running a Bash script and then print it on the terminal. Here I have developed a Bash script that takes input from the user and then prints it on the terminal. To do this task, follow the below script.<\/p>\n<p style=\"text-align: justify;\"><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=\"#steps_of_example_01\"><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.sh) &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#takeing input from users\nread -p &quot;What is your name?: &quot; name\n\n#printing on the terminal\necho &quot;Welcome $name!&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">At first, the Bash script asks for input from the user and keeps it on the name variable. Then the <strong>echo command<\/strong> prints a line on the terminal which contain the value of name variable.<\/p>\n<\/div><\/div>\n<p>Execute the following command into the terminal to make the Bash script executable.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">chmod +x bash.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 style=\"font-weight: 400;\" aria-level=\"1\"><strong><a href=\"https:\/\/linuxsimply.com\/chmod-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">chmod<\/a><\/strong><span style=\"font-weight: 400;\"><strong>:<\/strong> Change the permission of a file.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\"><strong>+x:<\/strong> Gives execution permission to all.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\"><strong>bash.sh:<\/strong> Bash script name.<\/span><\/li>\n<\/ul>\n<\/div><\/div>\n<p>Run the script by the following command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/bash.sh<\/code><\/pre>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-14433 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/2-read-echo-command.png\" alt=\"A Bash script is written in such a way that it takes a input from the user then print a message including the input value on the terminal.\" width=\"688\" height=\"221\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/2-read-echo-command.png 688w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/2-read-echo-command-300x96.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/2-read-echo-command-766x246.png 766w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/>In the above image, you can see that the Bash script has taken input from the user and then printed it on the terminal.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_03_Performing_Arithmetic_Operations_by_Taking_Two_Input_Numbers_from_the_User\"><\/span>Example 03: Performing Arithmetic Operations by Taking Two Input Numbers from the User<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Programmers can do <strong>arithmetic operations<\/strong> on the Bash script. Here, I have developed a Bash script that takes two inputs from the user and then does an arithmetic summation. Afterward, print the summation on the terminal. To do so, follow the below 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=\"#steps_of_example_01\"><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 (arith.sh) &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#taking number as input from user\nread -p &quot;Enter First Number: &quot; a\nread -p &quot;Enter Second Number: &quot; b\n\n#calculation summation\nvar=$((a+b))\n\n#printing the summation value\necho &quot;Summation of The Two Number:$var&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">At first, the Bash script has taken <strong>numbers a <\/strong>and<strong> b<\/strong> as input. Then I did the arithmetic summation. And finally, print the summation on the terminal.<\/p>\n<\/div><\/div>\n<p>Run the script by the following command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/arith.sh<\/code><\/pre>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-14434 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/3-arithmetic-operation.png\" alt=\"User inputs two numbers, then arithmetic summation is done.\" width=\"700\" height=\"256\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/3-arithmetic-operation.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/3-arithmetic-operation-300x110.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/3-arithmetic-operation-766x280.png 766w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>The above image shows that the Bash script has taken input from the user then done an arithmetic summation.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_04_Using_a_Function_in_the_Bash_Script\"><\/span>Example 04: Using a Function in the Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can easily use a function in the Bash script. Here, I have developed a Bash script where the <strong>function is used to print a message<\/strong>. To do so, follow the below 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=\"#steps_of_example_01\"><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_fun.sh) &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# A sample bash function\nsample_function () {\necho &quot;Good Morning!&quot;\n}\n\n# Invoking the sample_function\nsample_function<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">At first, a function named <strong>sample_function<\/strong> has been defined. In side the function the <strong>echo command<\/strong> prints a message. In the next part of the Bash script, sample_function has been called by simply putting the function name.<\/p>\n<\/div><\/div>\n<p>Run the script by the following command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/bash_fun.sh<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-14435 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/4-sample-function.png\" alt=\"A function is written inside a Bash script which printed a message on the terminal.\" width=\"700\" height=\"177\" data-wp-editing=\"1\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/4-sample-function.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/4-sample-function-300x76.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/4-sample-function-767x194.png 767w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>The above image shows that the Bash script has printed a message using a function.<\/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;\">Writing Bash script empowers you to <strong>automate repetitive tasks<\/strong>, <strong>manage complex operations<\/strong>, and boost your efficiency as a developer or system administrator. By understanding the fundamentals of Bash scripting, including the Bash symbol, shebang, script commands, and chaining multiple commands, you can create powerful scripts to streamline your workflow. Embrace the power of Bash scripting, and unlock new possibilities in the command line realm.<\/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<p><span style=\"font-weight: 400;\"><div class=\"su-accordion su-u-trim\"><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\"><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><strong>How do I write a bash script in shell?<\/strong><\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"> To produce a bash script, start the file with <strong>#!\/bin\/bash<\/strong>. Run <strong>.\/scriptname<\/strong> with any options to run the script from the current directory. The shell locates the #!\/path\/to\/interpreter when it runs a script. <\/div><\/div><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\"><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><strong>What is bash used for?<\/strong><\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"> Tasks like <strong>code compilation<\/strong>, <strong>source code debugging<\/strong>, <strong>change management<\/strong>, and <strong>software testing<\/strong> may all be automated with Bash. On workplace networks, network engineers use Bash to test, configure, and improve network performance. <\/div><\/div><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\"><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><strong>Is Bash faster than Python?<\/strong><\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"> A bash shell script starts up in 2.8 milliseconds, whereas PPython takes 11.1 milliseconds. Like Python, Bash is a <strong>general-purpose language<\/strong>, although both have advantages and disadvantages. Since the majority of Linux distributions use the Bash shell as the default terminal, it will always <strong>operate more quickly<\/strong>. <\/div><\/div><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\"><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><strong>Do programmers use bash?<\/strong><\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"> In order to deal with files and apps, save time, or make the most of restricted computer resources, developers on <strong>macOS and Linux<\/strong> PCs utilize Bash every day. <\/div><\/div><\/span><\/p>\n<p><span style=\"font-weight: 400;\"><\/div><\/span><\/p>\n<p><span style=\"color: #003366;\"><strong><span style=\"font-size: 18pt;\">Related Articles<\/span><\/strong><\/span><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/start-writing-bash-scripts\/\" target=\"_blank\" rel=\"noopener\">How Will You Start Writing Bash Scripts [A Complete Overview]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/what-is-shebang\/\" target=\"_blank\" rel=\"noopener\">An Ultimate Guide to Bin Bash Script and Shebang<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/commands\/\" target=\"_blank\" rel=\"noopener\">Most Used Bash Script Commands [The Ultimate Review]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/symbols\/\" target=\"_blank\" rel=\"noopener\">16 Most Used Symbols for Bash Script<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/chain-commands\/\" target=\"_blank\" rel=\"noopener\">8 Practical Examples of Chaining Commands in Bash Scripts<\/a><\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>&lt;&lt; Go Back to <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Scripting Basics&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:16768,&quot;10&quot;:1,&quot;11&quot;:4,&quot;17&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Basics<\/a><\/span>\u00a0| <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Tutorial<\/a><\/strong><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;14430&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;7&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;3.7&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;3.7\\\/5 - (7 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;Writing Bash Script&quot;,&quot;width&quot;:&quot;104.8&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: 104.8px;\">\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            3.7\/5 - (7 votes)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bash scripting is a powerful tool that allows you to automate tasks, streamline processes, and enhance your productivity as a &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Writing Bash Script\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#more-14430\" aria-label=\"Read more about Writing Bash Script\">Read more<\/a><\/p>\n","protected":false},"author":314894,"featured_media":14829,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[125],"class_list":["post-14430","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-bash-scripting-basics","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>Writing Bash Script - LinuxSimply<\/title>\n<meta name=\"description\" content=\"Bash programmer writes bash script to solve several problems, automate tasks etc. Here, I have discussed the basics of writing a Bash script.\" \/>\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\/basics\/writing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Writing Bash Script - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"Bash programmer writes bash script to solve several problems, automate tasks etc. Here, I have discussed the basics of writing a Bash script.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/dasgupta.susmit\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-31T04:44:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-23T05:41:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/writing-bash-script.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=\"Susmit Das Gupta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Susmit Das Gupta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/\"},\"author\":{\"name\":\"Susmit Das Gupta\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/38abbef9a1053d9faec8935dc39f10fa\"},\"headline\":\"Writing Bash Script\",\"datePublished\":\"2023-07-31T04:44:16+00:00\",\"dateModified\":\"2024-01-23T05:41:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/\"},\"wordCount\":1332,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/writing-bash-script.png\",\"keywords\":[\"bash scripting basics\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/\",\"name\":\"Writing Bash Script - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/writing-bash-script.png\",\"datePublished\":\"2023-07-31T04:44:16+00:00\",\"dateModified\":\"2024-01-23T05:41:48+00:00\",\"description\":\"Bash programmer writes bash script to solve several problems, automate tasks etc. Here, I have discussed the basics of writing a Bash script.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/writing-bash-script.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/writing-bash-script.png\",\"width\":400,\"height\":400,\"caption\":\"writing bash script\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/writing\\\/#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 Scripting Basics\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/basics\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Writing Bash Script\"}]},{\"@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\\\/38abbef9a1053d9faec8935dc39f10fa\",\"name\":\"Susmit Das Gupta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Susmit-Das-Gupta-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Susmit-Das-Gupta-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Susmit-Das-Gupta-II-96x96.png\",\"caption\":\"Susmit Das Gupta\"},\"description\":\"Hello everyone. I am Susmit Das Gupta, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Mechanical Engineering graduate from Bangladesh University of Engineering and Technology. Besides my routine works, I find interest in going through new things, exploring new places, and capturing landscapes. Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/dasgupta.susmit\",\"https:\\\/\\\/www.instagram.com\\\/susmit_dasgupta\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/susmitdasgupta\\\/\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/susmit\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Writing Bash Script - LinuxSimply","description":"Bash programmer writes bash script to solve several problems, automate tasks etc. Here, I have discussed the basics of writing a Bash script.","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\/basics\/writing\/","og_locale":"en_US","og_type":"article","og_title":"Writing Bash Script - LinuxSimply","og_description":"Bash programmer writes bash script to solve several problems, automate tasks etc. Here, I have discussed the basics of writing a Bash script.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/dasgupta.susmit","article_published_time":"2023-07-31T04:44:16+00:00","article_modified_time":"2024-01-23T05:41:48+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/writing-bash-script.png","type":"image\/png"}],"author":"Susmit Das Gupta","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Susmit Das Gupta","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/"},"author":{"name":"Susmit Das Gupta","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/38abbef9a1053d9faec8935dc39f10fa"},"headline":"Writing Bash Script","datePublished":"2023-07-31T04:44:16+00:00","dateModified":"2024-01-23T05:41:48+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/"},"wordCount":1332,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/writing-bash-script.png","keywords":["bash scripting basics"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/","name":"Writing Bash Script - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/writing-bash-script.png","datePublished":"2023-07-31T04:44:16+00:00","dateModified":"2024-01-23T05:41:48+00:00","description":"Bash programmer writes bash script to solve several problems, automate tasks etc. Here, I have discussed the basics of writing a Bash script.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/writing-bash-script.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/writing-bash-script.png","width":400,"height":400,"caption":"writing bash script"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/writing\/#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 Scripting Basics","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/"},{"@type":"ListItem","position":4,"name":"Writing Bash Script"}]},{"@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\/38abbef9a1053d9faec8935dc39f10fa","name":"Susmit Das Gupta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Susmit-Das-Gupta-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Susmit-Das-Gupta-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Susmit-Das-Gupta-II-96x96.png","caption":"Susmit Das Gupta"},"description":"Hello everyone. I am Susmit Das Gupta, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Mechanical Engineering graduate from Bangladesh University of Engineering and Technology. Besides my routine works, I find interest in going through new things, exploring new places, and capturing landscapes. Read Full Bio","sameAs":["https:\/\/www.facebook.com\/dasgupta.susmit","https:\/\/www.instagram.com\/susmit_dasgupta\/","https:\/\/www.linkedin.com\/in\/susmitdasgupta\/"],"url":"https:\/\/linuxsimply.com\/author\/susmit\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/14430","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\/314894"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=14430"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/14430\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/14829"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=14430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=14430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=14430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}