{"id":12817,"date":"2023-06-15T12:11:46","date_gmt":"2023-06-15T12:11:46","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=12817"},"modified":"2024-03-19T03:22:22","modified_gmt":"2024-03-19T03:22:22","slug":"linux-tutorial-bash-scripting","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/","title":{"rendered":"Bash Scripting Tutorial"},"content":{"rendered":"<p style=\"text-align: justify;\">In today\u2019s fast-paced world, automation has become essential for streamlining tasks and improving productivity. One powerful tool for process automation is <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/introduction\/what-is-bash-scripting\/\" target=\"_blank\" rel=\"noopener\"><strong>Bash scripting<\/strong><\/a>. <strong>Bash <\/strong>(<strong>Bourne Again SHell<\/strong>), is a versatile scripting language commonly used in <a href=\"https:\/\/linuxsimply.com\/what-is-unix-operating-system\/\" target=\"_blank\" rel=\"noopener\"><strong>Unix-based systems<\/strong><\/a>. In this <strong>Bash scripting tutorial<\/strong>, I will explore the world of Bash scripting and its capabilities for automating various tasks efficiently. Let\u2019s embark on a journey to becoming a proficient Bash scripter!<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Introduction_to_Bash_Scripting\" >Introduction to Bash Scripting<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Why_Use_Bash_Scripting\" >Why Use 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-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Scripting_Basics\" >Bash Scripting Basics<\/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\/#A_Subtle_Overview_of_Bash_Shell_Command_Line_Interface\" >A Subtle Overview of Bash Shell &amp; Command Line Interface<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Comments\" >Bash Comments<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Commenting_Steps_at_a_Glance\" >Commenting Steps at a Glance<\/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\/#Categories_of_Comments\" >Categories of Comments<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Concept_of_Variables_Data_Types_in_Bash\" >Concept of Variables &amp; Data Types in Bash<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#General_Declaration_Assignment_of_Variable\" >General Declaration &amp; Assignment of Variable<\/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\/#Accessing_Variables_Using_%E2%80%98\" >Accessing Variables Using \u2018$\u2019<\/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\/#Variable_Scopes_%E2%80%93_Global_VS_Local\" >Variable Scopes &#8211; Global VS Local<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#A_Global_Variable\" >A. Global Variable<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#B_Local_Variable\" >B. Local Variable<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Some_Variable_Types\" >Some Variable Types<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Quotes\" >Bash Quotes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Parameters\" >Bash Parameters<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Expansion\" >Bash Expansion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_IO\" >Bash I\/O<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Standard_Streams_stdin_stdout_stderr\" >Bash Standard Streams (stdin, stdout, stderr)<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#3_Special_File_Descriptors\" >3 Special File Descriptors<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Redirection\" >Bash Redirection<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Piping\" >Bash Piping<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Operator\" >Bash Operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Conditional_Statements\" >Bash Conditional Statements<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Different_Types_of_Conditional_Statements_With_Their_Simple_Structures\" >Different Types of Conditional Statements With Their Simple Structures<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Loops\" >Bash Loops<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Basic_Loop_Structures\" >Basic Loop Structures<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#A_For_Loop\" >A. For Loop<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#B_While_Loop\" >B. While Loop<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#C_Until_Loop\" >C. Until Loop<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Loop_Control_Statements\" >Loop Control Statements<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Array\" >Bash Array<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_String\" >Bash String<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Functions\" >Bash Functions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#A_Declaring_Function\" >A. Declaring Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#B_Calling_Function\" >B. Calling Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-37\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#C_Passing_Arguments\" >C. Passing Arguments<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-38\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#D_Return_Values\" >D. Return Values<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-39\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Files_Directories\" >Bash Files &amp; Directories<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-40\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#What_is_a_File_System\" >What is a File System?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-41\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#File_Types\" >File Types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-42\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Navigating_Operations\" >Navigating Operations<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-43\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#File_Permissions\" >File Permissions<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-44\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Ownership_Category\" >Ownership Category<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-45\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#File_Permission_Type\" >File Permission Type<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-46\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Changing_File_Permissions\" >Changing File Permissions<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-47\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#File_Extension\" >File Extension<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-48\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Bash_Error_Handling\" >Bash Error Handling<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-49\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-50\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#People_Also_Ask\" >People Also Ask<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-51\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#How_do_I_start_Bash_scripting\" >How do I start Bash scripting?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-52\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Is_Bash_scripting_easy\" >Is Bash scripting easy?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-53\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#What_is_Bash_scripting_tutorial\" >What is Bash scripting tutorial?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-54\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Where_can_I_learn_bash_scripting\" >Where can I learn bash scripting?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-55\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#Is_Bash_a_good_skill\" >Is Bash a good skill?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Introduction_to_Bash_Scripting\"><\/span>Introduction to Bash Scripting<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Whether you&#8217;re a network engineer, developer, data analyst, system administrator, or just a random user looking for process-automating tasks, <strong>Bash Scripting<\/strong> is the powerful part that optimizes your working efficiency in all <strong>Unix-like<\/strong> environments including various <a href=\"https:\/\/linuxsimply.com\/distribution-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>Linux distributions<\/strong><\/a>, <strong>macOS,<\/strong> and other <strong>Unix-based systems<\/strong>.<\/p>\n<p style=\"text-align: justify;\">Effectively, a <strong>Bash script<\/strong> is a plain text file loaded with a series of commands and computer programs written in the Bash programming language. Developers use Bash scripting to avoid repetitive tasks on the <strong>Linux filesystem<\/strong> and increase the efficiency of system administration, data deployment, automated backups, etc.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Why_Use_Bash_Scripting\"><\/span>Why Use Bash Scripting?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Bash scripting is commonly used for a variety of purposes due to its flexibility and power in automating tasks. Exercising Bash scripting upgrades your command-line skills. Here\u2019s why you should learn Bash scripting:<\/p>\n<ul>\n<li style=\"text-align: justify;\"><strong>Automation<\/strong>: To automate repetitive tasks and save time.<\/li>\n<li style=\"text-align: justify;\"><strong>Customization<\/strong>: To customize scripts as per preferences.<\/li>\n<li style=\"text-align: justify;\"><strong>Text Manipulation<\/strong>: To manipulate texts by performing operations like searching, extracting, and so on.<\/li>\n<li style=\"text-align: justify;\"><strong>Data Processing<\/strong>: To process the manipulated data effectively.<\/li>\n<li style=\"text-align: justify;\"><strong>System Administration<\/strong>: To maintain different configurations and servers.<\/li>\n<li style=\"text-align: justify;\"><strong>Efficiency<\/strong>: To handle multiple complex tasks within a single script.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Scripting_Basics\"><\/span>Bash Scripting Basics<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>Bash scripting<\/strong> involves understanding fundamental concepts such as <strong>variables<\/strong>, <strong>control structures<\/strong>, <strong>functions<\/strong>, <strong>parameters<\/strong>, etc. Variables in Bash are used to store and manipulate data. You can assign values to variables and access them later in the script. Control structures, like <strong>conditional statements (if-else, case)<\/strong> and <strong>looping constructs (for, while)<\/strong>, allow you to control the flow of execution and make decisions in your scripts. Functions provide modularity and code reusability by encapsulating a set of instructions that can be called multiple times.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"A_Subtle_Overview_of_Bash_Shell_Command_Line_Interface\"><\/span>A Subtle Overview of Bash Shell &amp; Command Line Interface<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The term <strong>\u2018<\/strong><a href=\"https:\/\/linuxsimply.com\/what-is-a-shell-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>shell<\/strong><\/a><strong>\u2019<\/strong> is a <a href=\"https:\/\/linuxsimply.com\/cli-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>command-line interface (CLI)<\/strong><\/a> that provides an interaction between the operating system and the user. There are many shells available there such as <a href=\"https:\/\/linuxsimply.com\/bash-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>Bash<\/strong><\/a>, <a href=\"https:\/\/linuxsimply.com\/cheat-sheets\/zsh\/\" target=\"_blank\" rel=\"noopener\"><strong>Z shell (zsh)<\/strong><\/a>, <strong>Korn shell (ksh)<\/strong>, <strong>C shell (csh)<\/strong>, <strong>Fish (Friendly Interactive Shell)<\/strong>, etc. Among all, <strong>Bash <\/strong>is one of the most commonly used command-line interpreters which is an <strong>open-source<\/strong> <a href=\"https:\/\/linuxsimply.com\/what-is-gnu\/\" target=\"_blank\" rel=\"noopener\"><strong>GNU project<\/strong><\/a>. It is written by Brian Jhan Fox as an updated version of the <strong>Bourne Shell program<\/strong> &#8216;<strong>sh<\/strong>&#8216;. This is the <strong>by-default<\/strong> login <strong>shell <\/strong>for most <strong>Linux distributions <\/strong>like <strong>Ubuntu<\/strong>, <strong>Debian<\/strong>, <strong>Fedora<\/strong>, <strong>CentOS<\/strong>, etc.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Comments\"><\/span>Bash Comments<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In Bash scripting, <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/comments\/\" target=\"_blank\" rel=\"noopener\"><strong>comments<\/strong><\/a> are the lines that start with a <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/comments\/bash-the-hash\/\" target=\"_blank\" rel=\"noopener\"><strong>hash symbol (#)<\/strong><\/a>. Generally, comments are ignored by the Bash interpreter during the command execution. Though comments are not executable, they play a significant role in documenting the Bash codes. Have a look at the following commenting steps in Bash:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Commenting_Steps_at_a_Glance\"><\/span>Commenting Steps at a Glance<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li style=\"text-align: justify;\">Create a file with a <strong>.sh<\/strong>\u00a0extension.<\/li>\n<li style=\"text-align: justify;\">Open the file in any text editor like <a href=\"https:\/\/linuxsimply.com\/nano-cheat-sheet\/\" target=\"_blank\" rel=\"noopener\"><strong>Nano<\/strong><\/a>, <a href=\"https:\/\/linuxsimply.com\/cheat-sheets\/vim\/\" target=\"_blank\" rel=\"noopener\"><strong>Vim<\/strong><\/a>, <a href=\"https:\/\/linuxsimply.com\/emacs-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>Emacs<\/strong><\/a>, etc.<\/li>\n<li style=\"text-align: justify;\">Append the following line at the beginning of the script that includes the <strong>Shebang\/Hashbang (#!)<\/strong>:\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash<\/code><\/pre>\n<\/li>\n<li style=\"text-align: justify;\">Then, write comments along with the programs in the script explaining the function of each coded line.<\/li>\n<li style=\"text-align: justify;\">Finally, save the script by clicking <strong>CTRL+S <\/strong>and exit by typing <strong>CTRL+X<\/strong>.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Categories_of_Comments\"><\/span>Categories of Comments<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Bash commenting can be of different categories:<\/p>\n<ul>\n<li style=\"text-align: justify;\"><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/comments\/single-line\/\" target=\"_blank\" rel=\"noopener\"><strong>Single-line comments<\/strong><\/a>: Comments placed at the <strong>start <\/strong>of a coded line with a <strong>#<\/strong>\u00a0and extended to the end of the line.<\/li>\n<li style=\"text-align: justify;\"><strong>Inline comments<\/strong>: Comments placed at the <strong>end <\/strong>of a coded line with a <strong>#<\/strong>.<\/li>\n<li style=\"text-align: justify;\"><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/comments\/multiple-line\/\" target=\"_blank\" rel=\"noopener\"><strong>Multiple-line comments<\/strong><\/a>: A series of <strong>single-line comments<\/strong> to explain a section of code.<\/li>\n<li style=\"text-align: justify;\"><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/comments\/block-comment\/\" target=\"_blank\" rel=\"noopener\"><strong>Block comments<\/strong><\/a>: Comments enclosed between the delimiter \u201c: &lt;&lt;&#8216;block_comment&#8217;\u201d and \u201cblock_comment\u201d to create a multiline comment block. It is recommended for <strong>larger documentation<\/strong>.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Concept_of_Variables_Data_Types_in_Bash\"><\/span>Concept of Variables &amp; Data Types in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/variables-in-bash-script\/\" target=\"_blank\" rel=\"noopener\"><strong>Variables<\/strong><\/a> are the most important component in Bash that help to store, read, access, and manipulate data throughout the script. In Bash, there are no specific data types. A variable can hold any kind of data such as <strong>character strings<\/strong>, <strong>integers<\/strong>, <strong>float values,<\/strong> etc.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"General_Declaration_Assignment_of_Variable\"><\/span>General Declaration &amp; Assignment of Variable<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">A simple process for <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/\" target=\"_blank\" rel=\"noopener\"><strong>declaring and assigning variables<\/strong><\/a>:<\/p>\n<ul style=\"text-align: justify;\">\n<li><strong>Selecting A Meaningful Variable Name: <\/strong>The foremost task is to name the variable appropriately with proper clarity of the function of the variable.<\/li>\n<li><strong>Declaring the Variable: <\/strong>With the aid of the \u2018<a href=\"https:\/\/linuxsimply.com\/declare-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>declare command<\/strong><\/a>\u2019, you can easily declare any variable explicitly in your script.<\/li>\n<li><strong>Assigning Values to the Variable: <\/strong>The last task is to put a value to the declared variable. You can assign <strong>strings<\/strong>, <strong>numeric values<\/strong>, and <strong>boolean <\/strong>values to the specific variable.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">A <strong>simple syntax<\/strong> to declare and assign values to a variable is:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">declare variable1\nvariable1= 41\n\ndeclare variable2\nvariable2= Linux<\/code><\/pre>\n<p align=\"left\"><div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#E8F9FC;border-color:#ffffff;color:#333333;\">In most cases, you can simply assign values to the variables without using the &#8216;declare&#8217; keyword.<\/div><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Accessing_Variables_Using_%E2%80%98\"><\/span>Accessing Variables Using \u2018$\u2019<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Whenever you feel to access and see a variable, just append a \u2018<strong>$<\/strong> <strong>(dollar)<\/strong>\u2019 symbol before the variable along with the <a href=\"https:\/\/linuxsimply.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a> just like the following:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">echo $variable1\necho $variable2<\/code><\/pre>\n<p style=\"text-align: justify;\">Another form to access a variable is \u2018<strong>${variableName}<\/strong>\u2019. This syntax is suitable for confusing situations regarding variable names. For example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">variable=Lin\necho The website is ${variable}uxSimply<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Variable_Scopes_%E2%80%93_Global_VS_Local\"><\/span>Variable Scopes &#8211; Global VS Local<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In Bash scripting, variables include different scopes. Among them, the <strong>two <\/strong>prominent types of variable scopes are <strong>global <\/strong>and <strong>local<\/strong>.<\/p>\n<h4 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"A_Global_Variable\"><\/span>A. Global Variable<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">In general, every variable you create in Bash is a global variable which means you can use them in any function, conditional statement, or loop, and access them from anywhere in the script.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"B_Local_Variable\"><\/span>B. Local Variable<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">The local variables are only confined to the blocks of code or functions where they are already declared. Bash doesn\u2019t understand local variables outside of those blocks. Basically, to create a local variable, you need to use the term <strong>\u2018local\u2019 <\/strong>before the variable name.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Some_Variable_Types\"><\/span>Some Variable Types<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In Bash, there may be a series of variables of different types. Each type serves a specific purpose in Bash scripting like below:<\/p>\n<p style=\"text-align: justify;\"><strong>1.<\/strong> <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/types\/built-in-variables\/\" target=\"_blank\" rel=\"noopener\"><strong>Built-in Variable<\/strong><\/a><\/p>\n<ul style=\"text-align: justify;\">\n<li>The Predefined variables by the Bash shell.<\/li>\n<li><strong>Example<\/strong>:<strong> $HOME <\/strong>(User\u2019s home directory), <strong>$PWD <\/strong>(User\u2019s current working directory).<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>2.<\/strong> <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/types\/environment-variables\/\" target=\"_blank\" rel=\"noopener\"><strong>Environment Variable<\/strong><\/a><\/p>\n<ul style=\"text-align: justify;\">\n<li>These variables store information about the environment.<\/li>\n<li><strong>Example<\/strong>:<strong> $PATH <\/strong>(The directories where executable files are located).<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>3.<\/strong> <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/types\/string-variable\/\" target=\"_blank\" rel=\"noopener\"><strong>String Variable<\/strong><\/a><\/p>\n<ul style=\"text-align: justify;\">\n<li>These variables hold any kind of text data.<\/li>\n<li><strong>Example<\/strong>:<strong> $name <\/strong>(User\u2019s name), <strong>$designation <\/strong>(User\u2019s designation).<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>4.<\/strong> <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/types\/array-variable\/\" target=\"_blank\" rel=\"noopener\"><strong>Array Variable<\/strong><\/a><\/p>\n<ul style=\"text-align: justify;\">\n<li>Array variables capture multiple values as an array.<\/li>\n<li><strong>Example<\/strong>:<strong> ${array[@]} <\/strong>(The array elements).<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>5.<\/strong> <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/types\/special-variables\/\" target=\"_blank\" rel=\"noopener\"><strong>Special Variable<\/strong><\/a><\/p>\n<ul style=\"text-align: justify;\">\n<li>Every special variable has a special &amp; specific meaning.<\/li>\n<li><strong>Example<\/strong>:<strong> $? <\/strong>(Exit status of the last command), <strong>$0 <\/strong>(Name of the executing script).<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>6.<\/strong> <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/types\/boolean-variables\/\" target=\"_blank\" rel=\"noopener\"><strong>Boolean Variable<\/strong><\/a><\/p>\n<ul style=\"text-align: justify;\">\n<li style=\"text-align: justify;\">These are not directly included in Bash, yet you can simulate them by using strings (<strong>true<\/strong> or <strong>false<\/strong>) or integers (<strong>0 <\/strong>for<strong> false <\/strong>or <strong>true <\/strong>for <strong>otherwise<\/strong>).<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>7.<\/strong> <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/types\/heredoc-variable\/\" target=\"_blank\" rel=\"noopener\"><strong>HereDoc Variable<\/strong><\/a><\/p>\n<ul>\n<li style=\"text-align: justify;\">These variables use the <strong>HereDoc construct<\/strong> to input multiline text.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Quotes\"><\/span>Bash Quotes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>Quotes <\/strong>are an important element in Bash that you can use to determine and manipulate strings. Typically, Bash uses spaces to determine separate values. So, while working with variables to store complex values, enclose your content in quotes that consider the enclosed contents as a single item. Here\u2019s a summary of <strong>three <\/strong>quoting mechanisms in Bash:<\/p>\n<p style=\"text-align: justify;\"><strong>1. Single Quotes<\/strong>:<\/p>\n<ul style=\"text-align: justify;\">\n<li>Preserve the literal value of each character of the enclosed string.<\/li>\n<li>No variable expansion occurs.<\/li>\n<\/ul>\n<pre><code class=\"language-bash\" data-line=\"\">name=&quot;A&quot;\necho &#039;Hello, $name!&#039;\n#Output: Hello, $name!<\/code><\/pre>\n<p style=\"text-align: justify;\"><strong>2. Double Quotes<\/strong>:<\/p>\n<ul style=\"text-align: justify;\">\n<li>Preserve the literal value of all characters within the enclosed string.<\/li>\n<li>Allow variable expansion.<\/li>\n<li>Variables within quotes are replaced with their values.<\/li>\n<\/ul>\n<pre><code class=\"language-bash\" data-line=\"\">name=&quot;A&quot;\necho &quot;Hello, $name!&quot;\n\n#Output: Hello, A!<\/code><\/pre>\n<p style=\"text-align: justify;\"><strong>3. Escape Quotes<\/strong>:<\/p>\n<ul>\n<li style=\"text-align: justify;\">Use a <strong>backslash (\\)<\/strong> before a literal quote character within a string enclosed by the same type of quotes.<\/li>\n<li style=\"text-align: justify;\">Prevents the shell from interpreting the literal quote as the end of the string.<\/li>\n<\/ul>\n<pre><code class=\"language-bash\" data-line=\"\">echo &#039;I\\&#039;m here.&#039;\u00a0\n\n#Output: I&#039;m here.<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Parameters\"><\/span>Bash Parameters<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In Bash scripting, a <strong>Bash parameter<\/strong> is the fundamental feature that allows Bash scripts to receive inputs from the command line and modifies the scripts\u2019 responses according to those inputs. Parameters can easily be referred to as command-line arguments that commonly indicate a piece of information or values that make your scripts more adaptable and user-friendly by passing these values to the scripts during execution.<\/p>\n<p>Here are a few parameters to get familiar with:<\/p>\n<ul>\n<li style=\"text-align: justify;\"><strong>Positional Parameter: <\/strong>Positional parameters refer to a set of variables that holds values when a script is invoked. You can access these parameters by using the special variables: <strong>$1<\/strong>, <strong>$2<\/strong>, <strong>$3<\/strong>, and so on.<\/li>\n<li style=\"text-align: justify;\"><strong>Optional Parameter: <\/strong>You can provide <strong>specific options<\/strong>, implement optional parameters, and get the script\u2019s response accordingly. Also, you can often identify optional parameters by <strong>short (preceeding -) <\/strong>or <strong>long options(two preceeding dashes \u2013)<\/strong>.<\/li>\n<li style=\"text-align: justify;\"><strong>Special Parameter<\/strong>: Bash special parameters are the values that retain specific information such as the name of the script, the exit status of the recent command, and the number of arguments passed to the script, etc.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Expansion\"><\/span>Bash Expansion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>Bash Expansion<\/strong> is the process of altering text using various mechanisms or constructs imparted by the Bash shell. These mechanisms let users manipulate variables, strings, and other input data. Some mostly used Bash expansions:<\/p>\n<ul>\n<li style=\"text-align: justify;\"><strong>Brace Expansion: <\/strong>A powerful feature, Brace expansion allows you to generate strings by specifying a set of values enclosed in curly braces \u2018<strong>{}<\/strong>\u2019. It lets you write more compact scripts.<\/li>\n<li style=\"text-align: justify;\"><strong>Tilde Expansion: <\/strong>Tilde expansion provides a convenient way to quickly navigate to specific users\u2019 home directories only by using the \u2018<strong>~<\/strong>\u2019 character, instead of typing the full paths.<\/li>\n<li style=\"text-align: justify;\"><strong>Parameter Expansion: <\/strong>Parameter Expansion simply defines the way of accessing the value of any variables in Bash.<\/li>\n<li style=\"text-align: justify;\"><strong>Variable Expansion: <\/strong>Variable expansion is the fundamental feature in Bash that allows you to work with dynamic data by substituting variable names with their actual values.<\/li>\n<li style=\"text-align: justify;\"><strong>Arithmetic Expansion: <\/strong>This expansion is a way to perform mathematical operations in a script. The proper syntax for this expansion is <strong>$((expression))<\/strong>.<\/li>\n<li style=\"text-align: justify;\"><strong>Glob Expansion &amp; Wildcard Expansion: <\/strong>Glob expansion (also known as <strong>Filename expansion<\/strong>) is a broader concept of matching files based on some specific patterns or criteria by using some <strong>wildcard characters<\/strong> like <strong>?<\/strong>, <strong>*<\/strong>, <strong>[..]<\/strong> where you need not list any filename individually. On the contrary, Wildcard expansion is a more specific term that is directly related to the wildcard characters.<\/li>\n<\/ul>\n<p>Some other Bash expansions are- <strong>Shell expansion<\/strong>, <strong>History expansion<\/strong>, <strong>Array expansion,<\/strong> etc.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Bash_IO\"><\/span>Bash I\/O<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Basically, there are a bunch of Bash commands that print out information to the terminal. While working on this shell, there are many times when you would like to save the output or pass the output as the input of another command. Being a shell, Bash supports these <strong>I\/O<\/strong>-related tasks for creating a user-friendly environment between users and the script.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Bash_Standard_Streams_stdin_stdout_stderr\"><\/span>Bash Standard Streams (stdin, stdout, stderr)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Streams refer to a <strong>continuous flow of data<\/strong> that either receives texts in or feeds texts out ceaselessly. These are the special channels that handle various <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/input\/\" target=\"_blank\" rel=\"noopener\"><strong>input<\/strong><\/a> and <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/\" target=\"_blank\" rel=\"noopener\"><strong>output<\/strong><\/a> operations like data capturing, manipulating, redirecting, appending, etc.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"3_Special_File_Descriptors\"><\/span>3 Special File Descriptors<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">In <strong>Bash <\/strong>and other <strong>Unix-like systems<\/strong>, every stream is identified by a <strong>file descriptor<\/strong>. As everything in Linux is assumed as files, it includes input and output too. Typically, the system allows each process to have up to <strong>nine <\/strong>open file descriptors. Among them, Bash reserves only the first <strong>three <\/strong>descriptors with their specific IDs. Here are the <strong>three <\/strong>standard streams with their IDs (<strong>file descriptors \u20180\u2019, \u20181\u2019, \u20182\u2019<\/strong>) that you can access whenever a process starts:<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-19484\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-inputoutput.png\" alt=\"Bash input\/output\" width=\"700\" height=\"150\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-inputoutput.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-inputoutput-300x64.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-inputoutput-765x164.png 765w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<ul>\n<li><strong>stdin<\/strong>: It continuously receives input data and can be redirected from other commands and files.<\/li>\n<li><strong>stdout<\/strong>: It displays output continuously and can be redirected to files and other commands.<\/li>\n<li><strong>stderr<\/strong>: It displays error messages and can be redirected to files and other commands.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Redirection\"><\/span>Bash Redirection<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/linuxsimply.com\/what-is-redirection-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>Redirection<\/strong><\/a> in Bash is a method of changing the sources and destinations of standard input, standard output, and standard error flexibly. Bash executes redirection which is useful for capturing input data from files, holding output, and handling errors. There are some redirection operators below with their basic syntaxes:<\/p>\n<p><strong>Redirecting Standard Input <\/strong>\u2192 \u2018<strong>&lt;<\/strong>\u2019<\/p>\n<ul>\n<li>Redirects the input of a command from a file despite typing manually.<\/li>\n<\/ul>\n<pre><code class=\"language-bash\" data-line=\"\">command &lt; input_file.txt<\/code><\/pre>\n<p><strong>Redirecting Standard Output <\/strong>\u2192 \u2018<strong>&gt;<\/strong>\u2019<\/p>\n<ul>\n<li>Redirects the output of a command to a file rather than displaying it on the terminal.<\/li>\n<li>Overwrites the file.<\/li>\n<\/ul>\n<pre><code class=\"language-bash\" data-line=\"\">command &gt; output_file.txt<\/code><\/pre>\n<p><strong>Appending Standard Output <\/strong>\u2192 \u2018<strong>&gt;&gt;<\/strong>\u2019<\/p>\n<ul>\n<li>Appends the output of a command to an existing file without overwriting its contents.<\/li>\n<\/ul>\n<pre><code class=\"language-bash\" data-line=\"\">command &gt;&gt; output_file.txt<\/code><\/pre>\n<p><strong>Redirecting Standard Error <\/strong>\u2192 \u2018<strong>2&gt;<\/strong>\u2019<\/p>\n<ul>\n<li>Redirects error messages produced by commands.<\/li>\n<\/ul>\n<pre><code class=\"language-bash\" data-line=\"\">command 2&gt; error.log<\/code><\/pre>\n<p><strong>Appending Standard Error <\/strong>\u2192 \u2018<strong>2&gt;&gt;<\/strong>\u2019<\/p>\n<ul>\n<li>Appends error messages to an existing file without overwriting its content.<\/li>\n<\/ul>\n<pre><code class=\"language-bash\" data-line=\"\">command 2&gt;&gt; error.log<\/code><\/pre>\n<p><strong>Redirecting Both<\/strong> <strong>Standard Output and Standard Error<\/strong><\/p>\n<ul>\n<li>Redirects both output and error using the \u2018<strong>&amp;&gt;<\/strong>\u2019\/\u2018<strong>&gt;&amp;<\/strong>\u2019\/\u2018<strong>2&gt;&amp;1<\/strong>\u2019 symbol.<\/li>\n<\/ul>\n<pre><code class=\"language-bash\" data-line=\"\">command 2&gt;&amp;1 &gt; output.log<\/code><\/pre>\n<p><strong>Appending Both<\/strong> <strong>Standard Output and Standard Error\u00a0<\/strong><\/p>\n<ul>\n<li>Appends both output and error without overwriting using the &#8216;<strong>&gt;&gt;<\/strong>&#8216; symbol.<\/li>\n<\/ul>\n<pre><code class=\"language-bash\" data-line=\"\">command 2&gt;&amp;1 &gt;&gt; output.log<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Piping\"><\/span>Bash Piping<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/linuxsimply.com\/what-is-piping-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>Piping <\/strong><\/a>is the core process of chaining together the standard output of one command with the standard input of another command to perform complex tasks. By using the <strong>Unix pipe character \u2018|\u2019<\/strong>, you can create command sequences.<\/p>\n<p><span style=\"color: #000000;\"><strong>Basic Syntax:<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">Command 1 | Command 2 | Command 3<\/code><\/pre>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-19482\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/bash-pipe.png\" alt=\"Bash piping\" width=\"825\" height=\"275\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/bash-pipe.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/bash-pipe-300x100.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/bash-pipe-768x256.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Operator\"><\/span>Bash Operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In Bash, <strong>operators <\/strong>are the <strong>characters <\/strong>or <strong>symbols <\/strong>that perform multiple operations on values, variables, and various types of expressions. Depending on what type of output you want from your scripts, you need to append operators within codes. Below are some basic operators in Bash:<\/p>\n<p><strong>1 Arithmetic Operators<\/strong>: Arithmetic operators perform simple mathematical expressions.<\/p>\n<ul>\n<li>Addition (+)<\/li>\n<li>Subtraction (-)<\/li>\n<li>Multiplication (*)<\/li>\n<li>Division (\/)<\/li>\n<li>Modulus (%)<\/li>\n<li>Exponentiation (**)<\/li>\n<\/ul>\n<p><strong>2. Logical\/Boolean Operators<\/strong>: Logical operators perform logical operations.<\/p>\n<ul>\n<li>Logical AND (&amp;&amp;)<\/li>\n<li>Logical OR (||)<\/li>\n<li>Logical NOT (!)<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>3. Comparison Operators<\/strong>: <strong><a id=\"Comparison-operators\"><\/a>Comparison operators<\/strong> compare expressions and evaluate their relationships. These are generally used in conditional statements and loops.<\/p>\n<ul>\n<li>Equal to (-eq)<\/li>\n<li>Not equal to (-ne)<\/li>\n<li>Less than (-lt)<\/li>\n<li>Less than or equal (-le)<\/li>\n<li>Greater than (-gt)<\/li>\n<li>Greater than or equal (-ge)<\/li>\n<\/ul>\n<p><strong>4. String Operators<\/strong>: String operators manipulate and compare strings.<\/p>\n<ul>\n<li>Equal to (=)<\/li>\n<li>Not equal to (!=)<\/li>\n<li>If the string is empty (-z)<\/li>\n<li>If the string is non-empty (-n)<\/li>\n<li>Concatenation (str1$str2)<\/li>\n<\/ul>\n<p><strong>5. Unary Operators<\/strong>: Unary operators perform specific operations on a single value or operand.<\/p>\n<ul>\n<li>Increment by 1 (++)<\/li>\n<li>Decrement by 1 (&#8211;)<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>6. File Test Operators<\/strong>: File test operators perform tests on files and directories &amp; to determine their properties. These are often used in conditional statements to make decisions regarding files and directories.<\/p>\n<ul>\n<li>File existence test (-e)<\/li>\n<li>Regular file test (-f)<\/li>\n<li>Block special file test (-b)<\/li>\n<li>Character special file test (-c)<\/li>\n<li>Non-empty file test (-s)<\/li>\n<li>Directory test (-d)<\/li>\n<li>Read permission check (-r)<\/li>\n<li>Write permission check (-w)<\/li>\n<li>Execution permission check (-x)<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Conditional_Statements\"><\/span>Bash Conditional Statements<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>Conditionals <\/strong>make your Bash scripts more versatile by allowing you to make decisions while executing different codes based on certain data or conditions in Bash. Generally, Bash offers various types of <strong>statements <\/strong>like <strong>if<\/strong>, <strong>if else<\/strong>, <strong>else if (elif)<\/strong>, etc. These statements enable different actions depending on the multiple outcomes of the conditional tests in Bash.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Different_Types_of_Conditional_Statements_With_Their_Simple_Structures\"><\/span>Different Types of Conditional Statements With Their Simple Structures<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A shorthand list of different conditional statements with their basic visual structures is given below:<\/p>\n<div class=\"su-table su-table-responsive su-table-alternate su-table-fixed\">\n<table style=\"width: 100%\" width=\"100%\">\n<tbody>\n<tr>\n<th width=\"195\"><strong>Conditional Statements<\/strong><\/th>\n<th width=\"405\"><strong>Simple Structure<\/strong><\/th>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;text-align: center\" width=\"195\"><strong>if<\/strong><\/td>\n<td style=\"vertical-align: middle\" width=\"405\">if [ condition ]; then<br \/>\n#Code to execute<br \/>\nfi<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;text-align: center\" width=\"195\"><strong>Nested if<\/strong><\/td>\n<td style=\"vertical-align: middle\" width=\"405\">if [ condition ]; then<br \/>\nif [ another_condition ]; then<br \/>\n#Code to execute<br \/>\nfi<br \/>\nfi<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;text-align: center\" width=\"195\"><strong>If else<\/strong><\/td>\n<td style=\"vertical-align: middle\" width=\"405\">if [ condition ]; then<br \/>\n#Code to execute<br \/>\nelse<br \/>\n#Another code to execute<br \/>\nfi<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;text-align: center\" width=\"195\"><strong>Else if<\/strong><\/td>\n<td style=\"vertical-align: middle\" width=\"405\">if [ condition ]; then<br \/>\n#Code to execute<br \/>\nelif [ another_condition ]; then<br \/>\n#Code to execute<br \/>\nelse<br \/>\n#Code to execute<br \/>\nfi<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: middle;text-align: center\" width=\"195\"><strong>case <\/strong><\/td>\n<td style=\"vertical-align: middle\" width=\"405\">case &#8220;$variable&#8221; in<br \/>\npattern1)<br \/>\n#Write code when pattern1 matches<br \/>\n;;<br \/>\npattern2)<br \/>\n#Write code when pattern2 matches<br \/>\n;;<br \/>\n*)<br \/>\n#Write code when no patterns match<br \/>\n;;<br \/>\nesac<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Loops\"><\/span>Bash Loops<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>Loops <\/strong>are the essential tool in Bash used for automating the tasks that need repetition. You can efficiently process data and handle different scenarios by taking a set of commands and running them multiple times until you reach the desired result.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Basic_Loop_Structures\"><\/span>Basic Loop Structures<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Following are <strong>three <\/strong>basic loop structures that you can use to perform the loop operations in Bash scripting:<\/p>\n<h4><span class=\"ez-toc-section\" id=\"A_For_Loop\"><\/span>A. For Loop<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>The <strong>for\u00a0loop<\/strong> iterates over the sequence of values like arrays, range of numbers, or list of items.<\/p>\n<p><strong><span style=\"color: #000000;\">Basic Syntax:<\/span><\/strong><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">for variable in values;\ndo\n#Command\ndone<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"B_While_Loop\"><\/span>B. While Loop<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">The <strong>while\u00a0loop<\/strong> is one of the easiest loops to work with in Bash. As long as the applied condition evaluates to true, the while loop repeatedly executes the given set of commands.<\/p>\n<p><span style=\"color: #000000;\"><strong>Basic Syntax:<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">while [ condition ];\ndo\n#Command\ndone<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"C_Until_Loop\"><\/span>C. Until Loop<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">The <strong>until loop<\/strong> is quite similar to the while loop. The only difference is it executes the given set of commands until the applied condition becomes true.<\/p>\n<p><span style=\"color: #000000;\"><strong>Basic Syntax:<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">until [ condition ];\ndo\n#Command\ndone<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Loop_Control_Statements\"><\/span>Loop Control Statements<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Following are<strong> three <\/strong>control statements that you can use to perform the loop operations in Bash scripting:<\/p>\n<ul>\n<li><strong>break<\/strong>: The break statement tells Bash to leave the loop straight away when a specific condition is met.<\/li>\n<li style=\"text-align: justify;\"><strong>continue<\/strong>: The continue statement tells Bash to skip the current iteration of the loop and proceed to the next iteration.<\/li>\n<li><strong>exit<\/strong>: The exit statement terminates the entire shell session.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Array\"><\/span>Bash Array<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>Arrays <\/strong>are <strong>data structures<\/strong> that contain multiple values under a single variable. You can use any variable as an array in Bash. Each and every value an array holds is known as an <strong>element<\/strong>. It\u2019s not necessary that the elements must be of similar type. Bash supports both associative arrays <strong>(Strings) <\/strong>and indexed arrays <strong>(Numerical indices: 0,1,2,3,..)<\/strong> and there is <strong>no limited size<\/strong> of the arrays.<\/p>\n<p style=\"text-align: justify;\">In Bash scripting, arrays provide a convenient way to store, and manage collections of data, and also, retrieve elements in a list format for performing specific operations. Actually, arrays are <strong>zero-based <\/strong>meaning that the <strong>first element<\/strong> of the array is indexed with \u2018<strong>0<\/strong>\u2019. Here is a little outline of how you can declare and work with Bash arrays:<\/p>\n<ul>\n<li style=\"text-align: justify;\"><strong>Declaring Array<\/strong>: Use the built-in \u2018<a href=\"https:\/\/linuxsimply.com\/declare-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>declare<\/strong><\/a>\u2019 command for an explicit declaration of an array.<\/li>\n<li style=\"text-align: justify;\"><strong>Printing Array Elements<\/strong>: After array declaration, use the syntax \u2018<strong>${array_name[@]}<\/strong>\u2019 to print and display all the array elements space-separated where \u2018<strong>[@]<\/strong>\u2019 represents the index.<\/li>\n<li style=\"text-align: justify;\"><strong>Iterating over Array<\/strong>: Use any <strong>loops <\/strong>to iterate over array elements.<\/li>\n<li style=\"text-align: justify;\"><strong>Inserting and Deleting Elements from Array<\/strong>: Add and delete elements from an array by setting the proper index of the element and using the \u2018<strong>unset<\/strong>\u2019 command respectively.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Bash_String\"><\/span>Bash String<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In Bash scripting, <strong>strings <\/strong>are the fundamental data types used to store text-based data. These are the sequence of characters including <strong>letters<\/strong>, <strong>symbols<\/strong>, and <strong>spaces<\/strong>. Bash strings also contain <strong>numbers <\/strong>or <strong>digits <\/strong>enclosed in <strong>single quotes<\/strong> <strong>\u00a0(&#8216;)<\/strong> or <strong>double quotes (&#8221;)<\/strong>. They play a crucial role in manipulating text and serving several purposes like processing user input, storing path information, etc. Here are some basic string operations in Bash:<\/p>\n<ul>\n<li style=\"text-align: justify;\"><strong>Defining String<\/strong>: Use single or double quotes to define strings. You can omit the quotes too, but there can\u2019t be any space either before or after the <strong>equal (=) <\/strong><\/li>\n<li style=\"text-align: justify;\"><strong>Reading String from User<\/strong>: Using the \u2018<strong>read<\/strong>\u2019 command, you can read the inserted input string of the user.<\/li>\n<li style=\"text-align: justify;\"><strong>String Concatenation<\/strong>: You can perform string concatenation by using the \u2018<strong>+<\/strong>\u2019 operator or listing the strings in order.<\/li>\n<li style=\"text-align: justify;\"><strong>String Length<\/strong>: You can find the length of a string by the placing \u2018<strong>#<\/strong>\u2019 operator inside the <strong>parameter expansion (curly braces)<\/strong> before the variable name like \u2018<strong>${#variable}<\/strong>\u2019.<\/li>\n<li style=\"text-align: justify;\"><strong>Substring Extraction<\/strong>: The syntax \u2018<strong>${string:start:length}<\/strong>\u2019 might help you to extract a substring from a string.<\/li>\n<li style=\"text-align: justify;\"><strong>Comparing Strings<\/strong>: By using the <a href=\"#Comparison-operators\"><strong>comparison operators<\/strong><\/a> you can compare strings.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Functions\"><\/span>Bash Functions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In Bash, a function is essentially a reusable set of commands under one name that you can call multiple times within your script. Whenever you need to perform certain tasks several times, instead of writing the codes repeatedly, you can write them once in a function and call that function multiple times.<\/p>\n<p style=\"text-align: justify;\">The <strong>Bash function<\/strong> really helps break down your scripts into smaller ones and make them more manageable and organized. Elementally, it\u2019s more like <strong>a script within a script<\/strong>.<\/p>\n<p>Now, take a look at how you can define and use functions in Bash:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"A_Declaring_Function\"><\/span>A. Declaring Function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can define functions in <strong>two <\/strong>formats:<\/p>\n<p><strong><span style=\"color: #800080;\">Format 1 &gt;<\/span> Mostly used format<\/strong><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">function_name () {\ncommands\n}<\/code><\/pre>\n<p><strong><span style=\"color: #800080;\">Format 2 &gt;<\/span> Using the reserved word \u2018function\u2019<\/strong><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">function function_name {\ncommands\n}<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"B_Calling_Function\"><\/span>B. Calling Function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">When you declare a function, it doesn\u2019t execute. It only executes when called after the declaration. So, call a function by simply writing its name and then execute the coded lines within it.<\/p>\n<h3 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"C_Passing_Arguments\"><\/span>C. Passing Arguments<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">It\u2019s so obvious to like a function to process data. For this, you need to pass input arguments to the function. No worry! Passing input data to a function is no different from passing command line arguments to a Bash script.<\/p>\n<p style=\"text-align: justify;\">Insert the parameters directly just after the function call and put spaces between the function name and the parameters. Also, you can use the arguments within <strong>double quotes<\/strong> to prevent unexpected errors in the Bash script. Moreover, to access the arguments within the function, you can use some special variables like <strong>$0<\/strong>, <strong>$1<\/strong>, <strong>$2<\/strong>, <strong>$*<\/strong>, <strong>$@<\/strong>, <strong>$#<\/strong>, etc.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"D_Return_Values\"><\/span>D. Return Values<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">When it comes to returning values, Bash functions differ from other programming languages. By default, Bash functions return the <strong>exit status<\/strong> of the last executed command to verify whether the function was successfully executed or not. Hereafter, you can use the keyword \u2018<strong>return<\/strong>\u2019 and the special variable \u2018<strong>$?<\/strong>\u2019 to indicate and capture the return values of the functions respectively in Bash.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Files_Directories\"><\/span>Bash Files &amp; Directories<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In Bash scripting, working with files and directories is a very common task. A <strong>File<\/strong> refers to the fundamental unit of data storage including text, program, binary data, configuration settings, etc. Let\u2019s have a look at the key aspects of Bash files!<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_a_File_System\"><\/span>What is a File System?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">A <strong>file system <\/strong>in Bash is a <strong>tree-like<\/strong> <strong>structure <\/strong>organized with a collection of files and folders. Below is a representation of a hierarchical file system topology:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-19478\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-file-system.png\" alt=\"Bash file system topology\" width=\"700\" height=\"378\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-file-system.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-file-system-300x162.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-file-system-767x414.png 767w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"File_Types\"><\/span>File Types<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>There are various types of files in Bash. Here are some common file types:<\/p>\n<ul>\n<li><strong>Regular File (-)<\/strong>: It contains data, text, images, etc.<\/li>\n<li style=\"text-align: justify;\"><strong>Special File<\/strong>: It specifies and gives access to the hardware devices. Such as device files, sockets, named pipes, etc.<\/li>\n<li><strong>Symbolic Link (l)<\/strong>: It points to other files or directories.<\/li>\n<li><strong>Directory (d)<\/strong>: It contains both regular and special files forming a hierarchy.<\/li>\n<\/ul>\n<p><strong><span style=\"font-weight: 400;\"><div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#E8F9FC;border-color:#ffffff;color:#333333;\">Note: Use the <\/span><a href=\"https:\/\/linuxsimply.com\/file-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">file command<\/a><span style=\"font-weight: 400;\"> to display the type of a file.<\/span><span style=\"font-weight: 400;\"><\/div><\/div><\/span><\/strong><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Navigating_Operations\"><\/span>Navigating Operations<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Here are some commonly used commands that you can use to perform navigating operations on Bash files &amp; directories:<\/p>\n<ul>\n<li><a href=\"https:\/\/linuxsimply.com\/cd-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>cd<\/strong><\/a>: Change the directory.<\/li>\n<li><a href=\"https:\/\/linuxsimply.com\/ls-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>ls<\/strong><\/a>: List files.<\/li>\n<li><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/cat-command\/\" target=\"_blank\" rel=\"noopener\"><strong>cat<\/strong><\/a>: Display file contents.<\/li>\n<li><a href=\"https:\/\/linuxsimply.com\/touch-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>touch<\/strong><\/a>: Create files.<\/li>\n<li><a href=\"https:\/\/linuxsimply.com\/mkdir-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>mkdir<\/strong><\/a>: Create directories.<\/li>\n<li><a href=\"https:\/\/linuxsimply.com\/cp-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>cp<\/strong><\/a>: Copy files.<\/li>\n<li><a href=\"https:\/\/linuxsimply.com\/mv-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>mv<\/strong><\/a>: Move or rename files.<\/li>\n<li><strong>rename<\/strong>: Rename files.<\/li>\n<li><a href=\"https:\/\/linuxsimply.com\/rm-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>rm<\/strong><\/a>: Remove files &amp; directories.<\/li>\n<li><a href=\"https:\/\/linuxsimply.com\/rmdir-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>rmdir<\/strong><\/a>: Remove empty files &amp; directories.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"File_Permissions\"><\/span>File Permissions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In <strong>Linux-based systems<\/strong>, file permissions are an essential feature to secure its filesystem. File permission actually depicts who can read, write, or execute a file or directory. Generally, you can represent file permissions using the <strong>octal values<\/strong> or a <strong>series of characters (typically, by a 10-character string)<\/strong> by appending various commands. Explore the following overviews of how file permissions work in Bash:<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Ownership_Category\"><\/span>Ownership Category<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><strong>Three <\/strong>primary categories of Linux users:<\/p>\n<ul>\n<li><strong>Owner\/User<\/strong>: The user who creates or owns the file or directory.<\/li>\n<li><strong>Group<\/strong>: A group of users can access permissions associated with a file.<\/li>\n<li><strong>Others<\/strong>: Any third-party users who are not the owner or part of the group.<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"File_Permission_Type\"><\/span>File Permission Type<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>For each ownership category, there are <strong>three <\/strong>types of file permissions:<\/p>\n<ul>\n<li><strong>Read (r)<\/strong><\/li>\n<li><strong>Write (w)<\/strong><\/li>\n<li><strong>Execute (x)<\/strong><\/li>\n<\/ul>\n<p><strong> <img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-19479\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/FIle-permission-in-Bash-script-1.png\" alt=\"Bash file permissions\" width=\"700\" height=\"343\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/FIle-permission-in-Bash-script-1.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/FIle-permission-in-Bash-script-1-300x147.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/FIle-permission-in-Bash-script-1-767x376.png 767w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/strong><\/p>\n<h4><span class=\"ez-toc-section\" id=\"Changing_File_Permissions\"><\/span>Changing File Permissions<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">You can easily <strong>alter file permissions<\/strong> using the <a href=\"https:\/\/linuxsimply.com\/chmod-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>chmod command<\/strong><\/a> <strong>(ch<\/strong>ange<strong> mod<\/strong>e<strong>)<\/strong>. You can specify permissions either in <strong>symbolic (symbols) <\/strong>or <strong>numeric (numbers) <\/strong>form.<\/p>\n<p><span style=\"color: #800080;\"><strong>Symbolic Form &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">chmod u+x, o+rw file.txt<\/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>chmod<\/strong>: Changes file permissions.<\/li>\n<li><strong>u+x, o+rw<\/strong>: Adds <strong>execute (x)<\/strong> permission for <strong>user (u)<\/strong>, and <strong>read-write (rw)<\/strong> permissions for <strong>others<\/strong>.<\/li>\n<li><strong>file.txt<\/strong>: The file name.<\/li>\n<\/ul>\n<\/div><\/div>\n<p><span style=\"color: #800080;\"><strong>Numeric Form &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">chmod 644 file.txt<\/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>644<\/strong>: Sets <strong>read (r)<\/strong> and <strong>write (w)<\/strong> permission for <strong>owner<\/strong>, and <strong>read-only<\/strong> for <strong>group <\/strong>and <strong>others<\/strong>.<\/li>\n<\/ul>\n<\/div><\/div>\n<p style=\"text-align: justify;\">Visit the guide <a href=\"https:\/\/linuxsimply.com\/chmod-recursive-directories-and-files\/\" target=\"_blank\" rel=\"noopener\"><strong>Change Permissions of Directories and Files Recursively with \u201cchmod\u201d<\/strong><\/a> to clearly understand <strong>File permissions<\/strong> <strong>in Bash<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"File_Extension\"><\/span>File Extension<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">A file extension is the part of a filename that indicates the type of the file and the program you should start to open the file. Some common file extensions:<\/p>\n<ul>\n<li><strong>.txt<\/strong>: Text file.<\/li>\n<li><strong>.sh<\/strong>: Shell script file.<\/li>\n<li><strong>.log<\/strong>: Log file.<\/li>\n<li><strong>.conf<\/strong>: Configuration file.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Bash_Error_Handling\"><\/span>Bash Error Handling<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">When it comes to Bash scripting, it\u2019s very important to make the script error-free while executing it. Without proper error handling, Bash scripts may stop executing and fail to provide useful information to the users which makes it more difficult to troubleshoot. Look at the following part to figure out some best practices for <strong>error handling<\/strong>:<\/p>\n<ul>\n<li style=\"text-align: justify;\"><strong>Detecting Exit Status<\/strong>: When the exit status of a command is <strong>zero<\/strong>, it means there is <strong>no error<\/strong>. On the contrary, if there are <strong>any errors<\/strong>, the exit status shows some <strong>non-zero value<\/strong>. So, by checking the values of the exit status you can determine if the command was successfully executed or not.<\/li>\n<li style=\"text-align: justify;\"><strong>Using \u2018if\u2019 Conditional Statements<\/strong>: You can check the exit status of specific commands by using the \u2018<strong>if<\/strong>\u2019 statements and take proper actions.<\/li>\n<li style=\"text-align: justify;\"><strong>Using \u2018set -e (errexit)\u2019 and \u2018set -u (nounset)\u2019 Options<\/strong>: In Bash, the \u2018<strong>set -e<\/strong>\u2019 option tells to exit the script instantly if a command returns any non-zero exit status. The \u2018<strong>set -u<\/strong>\u2019 option tells Bash to exit if any uninitialized variables are encountered. However, by using these options judiciously, your script will automatically exit if any errors occur which will help you to prevent further issues.<\/li>\n<li style=\"text-align: justify;\"><strong>Using \u2018set -v (verbose)\u2019 Option: <\/strong>Though the \u2018<strong>set -v<\/strong>\u2019 option does not affect error handling directly, it can help in debugging. You can enable the <strong>verbose mode<\/strong> by using the \u2018<strong>set -v<\/strong>\u2019 option which means the Bash will print commands before their execution for debugging purposes.<\/li>\n<li style=\"text-align: justify;\"><strong>Using \u2018trap\u2019 Command<\/strong>: The \u2018<strong>trap<\/strong>\u2019 command allows you to specify a set of commands to be executed when your script receives specific signals or exits. You can use this command to detect errors and perform cleanup tasks.<\/li>\n<li style=\"text-align: justify;\"><strong>Using Error Messages<\/strong>: Error messages are a fundamental aspect in case of error handling. These can help you find what went wrong with the Bash users or administrators and aid in debugging. You can use the <strong>echo<\/strong> <strong>command <\/strong>to print error messages in bash scripts.<\/li>\n<\/ul>\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;\">To wrap up, the bash scripting tutorial covers a wide range of topics related to automating tasks for <strong>Unix-like environments<\/strong>. Moreover, mastering Bash scripting is such a valuable skill that will help you to interact with your command line interface in a productive way and apply your knowledge to real-world cases.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"People_Also_Ask\"><\/span>People Also Ask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_start_Bash_scripting\"><\/span>How do I start Bash scripting?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Starting with Bash scripting is a great way to automate tasks and enhance your efficiency on Unix-like systems. Here are steps to help you get started with Bash scripting:<\/p>\n<ol>\n<li style=\"text-align: justify;\">First, learn the basics of bash. Familiarize yourself with basic Bash commands and concepts.<\/li>\n<li style=\"text-align: justify;\">Then, understand shell scripting basics.<\/li>\n<li style=\"text-align: justify;\">After that, set up a text editor for writing your scripts. Popular choices are Vim, Emacs, Nano, etc.<\/li>\n<li style=\"text-align: justify;\">Write your first Bash script, let&#8217;s say in the Nano editor. One simplest script to write is:<br \/>\n<code class=\"\" data-line=\"\">#! \/bin\/bash<\/code><br \/>\n<code class=\"\" data-line=\"\">echo &quot;Hello, World!&quot;<\/code><\/li>\n<li style=\"text-align: justify;\">Now, save the script &amp; exit the Nano editor.<\/li>\n<li style=\"text-align: justify;\">Finally, to execute the script type <code class=\"\" data-line=\"\">bash script.sh<\/code>.<\/li>\n<li style=\"text-align: justify;\">For advanced learning later introduce yourself with variables, conditional statements, loops, functions, etc.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Is_Bash_scripting_easy\"><\/span>Is Bash scripting easy?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Yes, in general when it comes to simple tasks and automation, a lot of new users find bash scripting easy to learn and use. However, as with any other programming language, the difficulty may increase with the complexity of the tasks you aim to cover.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_Bash_scripting_tutorial\"><\/span>What is Bash scripting tutorial?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">A bash scripting tutorial is a learning resource designed to teach individuals how to write scripts using the bash programming language. These tutorials typically cover various aspects of bash scripting, starting from the basics and progressing to more advanced topics.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Where_can_I_learn_bash_scripting\"><\/span>Where can I learn bash scripting?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">There are various online resources where you can learn Bash scripting. Some of the popular platforms and websites are the official bash documentation (<strong><a href=\"https:\/\/www.gnu.org\/software\/bash\/manual\/\" target=\"_blank\" rel=\"noopener\">GNU Manual<\/a><\/strong>), online tutorials (<strong><a href=\"https:\/\/www.w3schools.com\/\" target=\"_blank\" rel=\"noopener\">W3Schools<\/a><\/strong>, <a href=\"https:\/\/linuxsimply.com\/\" target=\"_blank\" rel=\"noopener\"><strong>LinuxSimply<\/strong><\/a>, <a href=\"https:\/\/www.tutorialspoint.com\/unix\/shell_scripting.htm\" target=\"_blank\" rel=\"noopener\"><strong>Tutorialspoint<\/strong><\/a>, and <a href=\"https:\/\/www.shellscript.sh\/\" target=\"_blank\" rel=\"noopener\"><strong>Shell Scripting Tutorial<\/strong><\/a>), and YouTube, books, Bash Academy, etc.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Is_Bash_a_good_skill\"><\/span>Is Bash a good skill?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\"><strong>Yes<\/strong>, Bash scripting is a good skill for any developer, system administrator, or power user who wants to automate repetitive tasks and make their workflow more efficient.<\/span><\/p>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"Is Bash scripting easy?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Yes, in general when it comes to simple tasks and automation, a lot of new users find bash scripting easy to learn and use. However, as with any other programming language, the difficulty may increase with the complexity of the tasks you aim to cover.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What is Bash scripting tutorial?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"A bash scripting tutorial is a learning resource designed to teach individuals how to write scripts using the bash programming language. These tutorials typically cover various aspects of bash scripting, starting from the basics and progressing to more advanced topics.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Where can I learn bash scripting?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"There are various online resources where you can learn Bash scripting. Some of the popular platforms and websites are the official bash documentation (GNU Manual), online tutorials (W3Schools, LinuxSimply, Tutorialspoint, and Shell Scripting Tutorial), and YouTube, books, Bash Academy, etc.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Is Bash a good skill?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Yes, Bash scripting is a good skill for any developer, system administrator, or power user who wants to automate repetitive tasks and make their workflow more efficient.\"\n    }\n  }]\n}\n<\/script><br \/>\n<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\/introduction\/\" target=\"_blank\" rel=\"noopener\">Introduction to Bash Scripting<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Basics<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/comments\/\" target=\"_blank\" rel=\"noopener\">Bash Comments<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/\" target=\"_blank\" rel=\"noopener\">Bash Variables<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/quotes\/\" target=\"_blank\" rel=\"noopener\">Bash Quotes<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/\" target=\"_blank\" rel=\"noopener\">Parameters in Bash Scripting<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/expansion\/\" target=\"_blank\" rel=\"noopener\">An Overview of Shell Expansion in Bash<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/\" target=\"_blank\" rel=\"noopener\">Bash I\/O<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/redirection-and-piping\/\" target=\"_blank\" rel=\"noopener\">Bash Redirection and Piping<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/\" target=\"_blank\" rel=\"noopener\">Bash Operator<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/\" target=\"_blank\" rel=\"noopener\">Bash Conditional Statements<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/loop\/\" target=\"_blank\" rel=\"noopener\">Loops in Bash<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/array\/\" target=\"_blank\" rel=\"noopener\">Bash Array<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/\" target=\"_blank\" rel=\"noopener\">Bash String<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/\" target=\"_blank\" rel=\"noopener\">Bash Functions<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/files-and-directories\/\" target=\"_blank\" rel=\"noopener\">Bash Files and Directories<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/\" target=\"_blank\" rel=\"noopener\">Bash Error Handling and Debugging<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/process-and-signal-handling\/\" target=\"_blank\" rel=\"noopener\">Bash Process and Signal Handling<\/a><\/strong><\/li>\n<\/ul>\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;12817&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;29&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;4.8&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;4.8\\\/5 - (29 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;Bash Scripting Tutorial&quot;,&quot;width&quot;:&quot;136.7&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: 136.7px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            4.8\/5 - (29 votes)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>In today\u2019s fast-paced world, automation has become essential for streamlining tasks and improving productivity. One powerful tool for process automation &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Bash Scripting Tutorial\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#more-12817\" aria-label=\"Read more about Bash Scripting Tutorial\">Read more<\/a><\/p>\n","protected":false},"author":314905,"featured_media":22795,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_wp_convertkit_post_meta":{"form":"-1","landing_page":"0","tag":"0","restrict_content":"0"},"footnotes":""},"categories":[148],"tags":[135],"class_list":["post-12817","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn-linux","tag-linux-tutorial","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Bash Scripting Tutorial<\/title>\n<meta name=\"description\" content=\"Explore the Bash scripting tutorial and automate tasks with efficiency. Unleash the potential of automation using versatile scripting.\" \/>\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\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bash Scripting Tutorial\" \/>\n<meta property=\"og:description\" content=\"Explore the Bash scripting tutorial and automate tasks with efficiency. Unleash the potential of automation using versatile scripting.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/nadiba.rahman?mibextid=ZbWKwL\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-15T12:11:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-19T03:22:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Scripting-Tutorial-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"303\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nadiba Rahman\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nadiba Rahman\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"22 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\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\"},\"author\":{\"name\":\"Nadiba Rahman\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/69b717a03a5d9dc48e683aaffe22d33f\"},\"headline\":\"Bash Scripting Tutorial\",\"datePublished\":\"2023-06-15T12:11:46+00:00\",\"dateModified\":\"2024-03-19T03:22:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\"},\"wordCount\":4727,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Bash-Scripting-Tutorial-2.png\",\"keywords\":[\"linux tutorial\"],\"articleSection\":[\"Learn Linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\",\"name\":\"Bash Scripting Tutorial\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Bash-Scripting-Tutorial-2.png\",\"datePublished\":\"2023-06-15T12:11:46+00:00\",\"dateModified\":\"2024-03-19T03:22:22+00:00\",\"description\":\"Explore the Bash scripting tutorial and automate tasks with efficiency. Unleash the potential of automation using versatile scripting.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Bash-Scripting-Tutorial-2.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Bash-Scripting-Tutorial-2.png\",\"width\":400,\"height\":303},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash Scripting Tutorial\"}]},{\"@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\\\/69b717a03a5d9dc48e683aaffe22d33f\",\"name\":\"Nadiba Rahman\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Nadiba-Rahman-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Nadiba-Rahman-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Nadiba-Rahman-II-96x96.png\",\"caption\":\"Nadiba Rahman\"},\"description\":\"Hello, This is Nadiba Rahman, currently working as a Linux Content Developer Executive at SOFTEKO. I have completed my graduation with a bachelor\u2019s degree in Electronics &amp; Telecommunication Engineering from Rajshahi University of Engineering &amp; Technology (RUET).I am quite passionate about crafting. I really adore exploring and learning new things which always helps me to think transparently. And this curiosity led me to pursue knowledge about Linux. My goal is to portray Linux-based practical problems and share them with you. Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/nadiba.rahman?mibextid=ZbWKwL\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/nadiba-rahman-443459171\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/nadiba\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bash Scripting Tutorial","description":"Explore the Bash scripting tutorial and automate tasks with efficiency. Unleash the potential of automation using versatile scripting.","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\/","og_locale":"en_US","og_type":"article","og_title":"Bash Scripting Tutorial","og_description":"Explore the Bash scripting tutorial and automate tasks with efficiency. Unleash the potential of automation using versatile scripting.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/nadiba.rahman?mibextid=ZbWKwL","article_published_time":"2023-06-15T12:11:46+00:00","article_modified_time":"2024-03-19T03:22:22+00:00","og_image":[{"width":400,"height":303,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Scripting-Tutorial-2.png","type":"image\/png"}],"author":"Nadiba Rahman","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nadiba Rahman","Est. reading time":"22 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/"},"author":{"name":"Nadiba Rahman","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/69b717a03a5d9dc48e683aaffe22d33f"},"headline":"Bash Scripting Tutorial","datePublished":"2023-06-15T12:11:46+00:00","dateModified":"2024-03-19T03:22:22+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/"},"wordCount":4727,"commentCount":1,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Scripting-Tutorial-2.png","keywords":["linux tutorial"],"articleSection":["Learn Linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/","name":"Bash Scripting Tutorial","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Scripting-Tutorial-2.png","datePublished":"2023-06-15T12:11:46+00:00","dateModified":"2024-03-19T03:22:22+00:00","description":"Explore the Bash scripting tutorial and automate tasks with efficiency. Unleash the potential of automation using versatile scripting.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Scripting-Tutorial-2.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/06\/Bash-Scripting-Tutorial-2.png","width":400,"height":303},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxsimply.com\/"},{"@type":"ListItem","position":2,"name":"Bash Scripting Tutorial"}]},{"@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\/69b717a03a5d9dc48e683aaffe22d33f","name":"Nadiba Rahman","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Nadiba-Rahman-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Nadiba-Rahman-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Nadiba-Rahman-II-96x96.png","caption":"Nadiba Rahman"},"description":"Hello, This is Nadiba Rahman, currently working as a Linux Content Developer Executive at SOFTEKO. I have completed my graduation with a bachelor\u2019s degree in Electronics &amp; Telecommunication Engineering from Rajshahi University of Engineering &amp; Technology (RUET).I am quite passionate about crafting. I really adore exploring and learning new things which always helps me to think transparently. And this curiosity led me to pursue knowledge about Linux. My goal is to portray Linux-based practical problems and share them with you. Read Full Bio","sameAs":["https:\/\/www.facebook.com\/nadiba.rahman?mibextid=ZbWKwL","https:\/\/www.linkedin.com\/in\/nadiba-rahman-443459171"],"url":"https:\/\/linuxsimply.com\/author\/nadiba\/"}]}},"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/12817","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\/314905"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=12817"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/12817\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/22795"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=12817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=12817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=12817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}