{"id":35423,"date":"2024-01-30T06:53:24","date_gmt":"2024-01-30T06:53:24","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=35423"},"modified":"2024-02-11T07:29:03","modified_gmt":"2024-02-11T07:29:03","slug":"bash-set","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/","title":{"rendered":"How to Debug Bash Script with \u201cset\u201d Command? [3 Cases]"},"content":{"rendered":"<p style=\"text-align: justify;\">The <strong>set command <\/strong>in bash is one of the most powerful tools in bash. It has many functionalities such as enabling debugging to manipulate the positional parameters. However, in this article, I am going to talk about the role set command plays in bash debugging with some examples. So let&#8217;s get started!<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/Practice_Files_bash-set.zip\" class=\"su-button su-button-style-default\" style=\"color:#000000;background-color:#E8F9FF;border-color:#bac8cc;border-radius:56px\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color:#000000;padding:8px 26px;font-size:20px;line-height:30px;border-color:#effbff;border-radius:56px;text-shadow:0px 0px 0px #000000\"><i class=\"sui sui-download\" style=\"font-size:20px;color:#1AA1D6\"><\/i> Practice Files to Debug Bash Script with \u201cset\u201d Command<\/span><\/a><\/div>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#What_is_%E2%80%9Cset%E2%80%9D_Command_in_Bash\" >What is \u201cset\u201d Command in Bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#Role_of_Set_Command_in_Bash_Debugging\" >Role of Set Command in Bash Debugging<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#3_Practical_Cases_of_%E2%80%9Cset%E2%80%9D_Command_in_Bash_Debugging\" >3 Practical Cases of \u201cset\u201d Command in Bash Debugging<\/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\/error-handling-and-debugging\/debugging\/bash-set\/#1_Activate_Debug_Mode_Using_%E2%80%9Cset_-x%E2%80%9D_Command_in_Bash\" >1. Activate Debug Mode Using \u201cset -x\u201d Command in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#2_Enable_Verbose_Mode_Using_%E2%80%9Cset_-v%E2%80%9D_Command_in_Bash\" >2. Enable Verbose Mode Using \u201cset -v\u201d Command in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#3_Check_Unset_Variable_Using_%E2%80%9Cset_-u%E2%80%9D_Command_in_Bash\" >3. Check Unset Variable Using \u201cset -u\u201d Command in Bash<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#Conclusion\" >Conclusion<\/a><\/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\/error-handling-and-debugging\/debugging\/bash-set\/#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-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#How_to_set_debug_in_bash_script\" >How to set debug in bash script?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#How_do_I_set_debug_mode_in_Linux\" >How do I set debug mode in Linux?<\/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\/error-handling-and-debugging\/debugging\/bash-set\/#What_is_the_use_of_set_E_in_Bash\" >What is the use of set +E in Bash?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"What_is_%E2%80%9Cset%E2%80%9D_Command_in_Bash\"><\/span>What is \u201cset\u201d Command in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In Bash, the &#8216;set&#8217; command is a built-in command that alters the shell&#8217;s behaviour and attributes. With various options, it enables or disables settings, <strong>modifies shell attributes<\/strong>, <strong>sets positional parameters<\/strong>, and adjusts the <strong>internal field separator<\/strong>. Moreover, it provides control over script execution, error handling, debugging, and more.<\/p>\n<p style=\"text-align: justify;\">The basic syntax of the set command in Bash is as follows:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">set [options]<\/code><\/pre>\n<p style=\"text-align: justify;\">Here, <code class=\"\" data-line=\"\">[options]<\/code> represents various command-line options that modify the behaviour of the shell.<\/p>\n<p style=\"text-align: justify;\">Check the list of options down below that can be used with the set command in bash:<\/p>\n<p><span style=\"font-weight: 400;\"><div class=\"su-table su-table-responsive su-table-alternate su-table-fixed\"><\/span><\/p>\n<table style=\"height: 585px;width: 100%\">\n<tbody>\n<tr style=\"height: 51px\">\n<td style=\"width: 19.798%;height: 51px;vertical-align: middle;text-align: center\" width=\"115\"><strong>Option<\/strong><\/td>\n<td style=\"width: 79.596%;height: 51px;vertical-align: middle;text-align: center\" width=\"485\"><strong>Functionality<\/strong><\/td>\n<\/tr>\n<tr style=\"height: 51px\">\n<td style=\"width: 19.798%;vertical-align: middle;text-align: center;height: 51px\" width=\"115\">-e<\/td>\n<td style=\"width: 79.596%;vertical-align: middle;text-align: center;height: 51px\" width=\"485\">Exit immediately if any command exits with a<strong> non-zero status<\/strong>, signaling an error.<\/td>\n<\/tr>\n<tr style=\"height: 51px\">\n<td style=\"width: 19.798%;vertical-align: middle;text-align: center;height: 51px\" width=\"115\">-u<\/td>\n<td style=\"width: 79.596%;vertical-align: middle;text-align: center;height: 51px\" width=\"485\">Treat unset variables as an error, preventing the use of <strong>undefined<\/strong> <strong>variables<\/strong>.<\/td>\n<\/tr>\n<tr style=\"height: 76px\">\n<td style=\"width: 19.798%;vertical-align: middle;text-align: center;height: 76px\" width=\"115\">-x<\/td>\n<td style=\"width: 79.596%;vertical-align: middle;text-align: center;height: 76px\" width=\"485\">Print each command and its arguments to the <strong>standard<\/strong> <strong>error<\/strong> output before executing, aiding in script debugging.<\/td>\n<\/tr>\n<tr style=\"height: 51px\">\n<td style=\"width: 19.798%;vertical-align: middle;text-align: center;height: 51px\" width=\"115\">-o<\/td>\n<td style=\"width: 79.596%;vertical-align: middle;text-align: center;height: 51px\" width=\"485\">Enable or disable a specific <strong>shell<\/strong> <strong>option<\/strong>, providing fine-grained control over script behavior.<\/td>\n<\/tr>\n<tr style=\"height: 51px\">\n<td style=\"width: 19.798%;vertical-align: middle;text-align: center;height: 51px\" width=\"115\">-E<\/td>\n<td style=\"width: 79.596%;vertical-align: middle;text-align: center;height: 51px\" width=\"485\">Preserve the environment when executing shell functions, ensuring access to variables and settings.<\/td>\n<\/tr>\n<tr style=\"height: 76px\">\n<td style=\"width: 19.798%;vertical-align: middle;text-align: center;height: 76px\" width=\"115\">-n<\/td>\n<td style=\"width: 79.596%;vertical-align: middle;text-align: center;height: 76px\" width=\"485\">Read commands but do not execute them, useful for <strong>syntax<\/strong> <strong>checking<\/strong> and debugging without actual execution.<\/td>\n<\/tr>\n<tr style=\"height: 51px\">\n<td style=\"width: 19.798%;vertical-align: middle;text-align: center;height: 51px\" width=\"115\">-v<\/td>\n<td style=\"width: 79.596%;vertical-align: middle;text-align: center;height: 51px\" width=\"485\">Print shell input lines as they are read, assisting in understanding script execution and <strong>identifying<\/strong> <strong>errors<\/strong>.<\/td>\n<\/tr>\n<tr style=\"height: 76px\">\n<td style=\"width: 19.798%;vertical-align: middle;text-align: center;height: 76px\" width=\"115\">-C<\/td>\n<td style=\"width: 79.596%;vertical-align: middle;text-align: center;height: 76px\" width=\"485\">Turn off <strong>case<\/strong>&#8211;<strong>insensitive<\/strong> filename completion, affecting how file and directory names are handled in the shell.<\/td>\n<\/tr>\n<tr style=\"height: 51px\">\n<td style=\"width: 19.798%;vertical-align: middle;text-align: center;height: 51px\" width=\"115\">-h<\/td>\n<td style=\"width: 79.596%;vertical-align: middle;text-align: center;height: 51px\" width=\"485\">Display a <strong>summary<\/strong> of available options for the &#8220;set&#8221; command, providing a quick reference for users.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Role_of_Set_Command_in_Bash_Debugging\"><\/span>Role of Set Command in Bash Debugging<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">The <strong>set command <\/strong>in bash debugging is an essential tool for developers. With specific options, this command can print each line of a script before its execution. This allows the developer to identify any errors that may exist and correct them accordingly. One of the most popular features of the set command in bash debugging is the &#8220;set -x&#8221; command, which helps to understand the flow of script execution and detect errors. Additionally, &#8220;set -u&#8221; treats unset variables as an error, so you don&#8217;t have to worry about <strong>uninitialized variable <\/strong>issues.<\/p>\n<p style=\"text-align: justify;\">However, It is important to disable the debugging options before deploying your scripts to production to avoid verbosity and security risks.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"3_Practical_Cases_of_%E2%80%9Cset%E2%80%9D_Command_in_Bash_Debugging\"><\/span>3 Practical Cases of \u201cset\u201d Command in Bash Debugging<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">As mentioned, the <strong>set<\/strong> <strong>command<\/strong> is a handful and effective tool for <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/\" target=\"_blank\" rel=\"noopener\"><strong>Bash<\/strong> <strong>Debugging<\/strong><\/a>. Here, there are three examples are going to be discussed in the following section of the article.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Activate_Debug_Mode_Using_%E2%80%9Cset_-x%E2%80%9D_Command_in_Bash\"><\/span>1. Activate Debug Mode Using \u201cset -x\u201d Command in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To activate the <strong>debug mode <\/strong>in Bash using the <strong>set -x<\/strong> <strong>command<\/strong>, you simply include the following line at the beginning of your Bash script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nset -x\u00a0 # Activate debug mode\n\n# Rest of your script<\/code><\/pre>\n<p style=\"text-align: justify;\">You can also use an alternative approach like using <code class=\"\" data-line=\"\">set -o xtrace<\/code> command to active the <strong>debug<\/strong> <strong>mode<\/strong> as follows:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nset -o xtrace\u00a0 # Activate debug mode\n\n# Rest of your script<\/code><\/pre>\n<p style=\"text-align: justify;\">When <code class=\"\" data-line=\"\">set -x<\/code> is used, each command and its arguments will be printed to the standard error output before execution.\u00a0 See the following example code to understand its functionality:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nset -x  # Enable debugging output\n\nfunction greet {\n    local name=$1\n    echo &quot;Hello, $name!&quot;\n}\n\necho &quot;Script starting...&quot;\n\nname=&quot;John&quot;\ngreet &quot;$name&quot;\n\nfor number in {1..3}; do\n    result=$((number * 2))\n    echo &quot;Result: $result&quot;\ndone\n\nset +x  # Disable debugging output\n\necho &quot;Script ending...&quot;\n<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">The provided Bash script begins with <code class=\"\" data-line=\"\">#!\/bin\/bash<\/code>, indicating that it is a Bash script. Next, <code class=\"\" data-line=\"\">set -x<\/code> turns on debugging output, so that each command and all of its arguments will be printed to standard error before execution. Then, the greet function is called to display a customized greeting using the given name. After that, the script will <code class=\"\" data-line=\"\">echo &quot;script starting...&quot;<\/code> and set the variable name \u201cJohn\u201d. Then, the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/loop\/for-loop\/\" target=\"_blank\" rel=\"noopener\"><strong>for loop<\/strong><\/a> will iterate three times, counting and repeating a doubled result each time. Finally, the <code class=\"\" data-line=\"\">set +x<\/code> line is used to turn off debugging output. The script finally displays \u201cScript ending\u201d with the help of <a href=\"https:\/\/linuxsimply.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a>.<\/div><\/div><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-35431 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/1.-Output-image-after-activating-the-debug-Mode-Using-set-x-Command-in-Bash.png\" alt=\"Output image after activating the debug Mode Using \u201cset -x\u201d Command in Bash\" width=\"533\" height=\"740\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/1.-Output-image-after-activating-the-debug-Mode-Using-set-x-Command-in-Bash.png 533w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/1.-Output-image-after-activating-the-debug-Mode-Using-set-x-Command-in-Bash-216x300.png 216w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/>As you can see from the image, the \u201cset -x\u201d command enables the display of the script line before its execution, and \u201cset +x\u201d disables the facility at the end of the code.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Enable_Verbose_Mode_Using_%E2%80%9Cset_-v%E2%80%9D_Command_in_Bash\"><\/span>2. Enable Verbose Mode Using \u201cset -v\u201d Command in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To enable <strong>verbose mode <\/strong>in Bash using the<strong> set -v command<\/strong>, include the following line at the beginning of your Bash script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nset -v  # Enable verbose mode\n\n# Rest of your script\n\nYou can also go for an alternative approach to debug your bash script with verbose mode as follows:\n#!\/bin\/bash\nset -o verbose  # Enable verbose mode\n\n# Rest of your script\nLet\u2019s see an example relevant to this:\n#!\/bin\/bash\n\nset -v  # Enable verbose mode\n\nfunction greet {\n    local name=$1\n    echo &quot;Hello, $name!&quot;\n}\n\necho &quot;Script starting...&quot;\n\nname=&quot;John&quot;\ngreet &quot;$name&quot;\n\nfor number in {1..3}; do\n    result=$((number * 2))\n    echo &quot;Result: $result&quot;\ndone\n\nset +v  # Disable verbose mode\n\necho &quot;Script ending...&quot;\n<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">In this given bash code, <code class=\"\" data-line=\"\">set -v<\/code> is used to enable verbose mode, printing each command to the standard error output before execution. The script defines a greet function and <code class=\"\" data-line=\"\">echoes &quot;Script starting...&quot;<\/code> before setting the variable name to &#8220;John&#8221; and calling the greet function. A <strong>for<\/strong> <strong>loop<\/strong> calculates and echoes doubled results for three iterations. <code class=\"\" data-line=\"\">set +v<\/code> is then used to disable <strong>verbose<\/strong> <strong>mode<\/strong>, and the script concludes with &#8220;Script ending&#8230;&#8221; echoing to signify the end of execution.<\/div><\/div>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter wp-image-35432 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/2.-Output-image-after-Enabling-Verbose-Mode-Using-set-v-Command-in-Bash.png\" alt=\"Output image after Enabling Verbose Mode Using \u201cset -v\u201d Command in Bash\" width=\"697\" height=\"772\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/2.-Output-image-after-Enabling-Verbose-Mode-Using-set-v-Command-in-Bash.png 697w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/2.-Output-image-after-Enabling-Verbose-Mode-Using-set-v-Command-in-Bash-271x300.png 271w\" sizes=\"(max-width: 697px) 100vw, 697px\" \/>As you can see from the image given above, the <strong>set -v command<\/strong> in the bash script displays the script line before their execution.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Check_Unset_Variable_Using_%E2%80%9Cset_-u%E2%80%9D_Command_in_Bash\"><\/span>3. Check Unset Variable Using \u201cset -u\u201d Command in Bash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">When you use <strong>set -u<\/strong> in a Bash script, you are enabling a setting that treats <strong>unset variables <\/strong>as errors. This is a safety measure to ensure that your script doesn&#8217;t inadvertently use variables that have not been defined.<\/p>\n<p style=\"text-align: justify;\">Here&#8217;s an example script demonstrating the use of <strong>set -u<\/strong>:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nset -u  # Enable treating unset variables as errors\n\necho &quot;Script starting...&quot;\n\n# Using the defined variable\ndefined_variable=&quot;I am defined.&quot;\necho &quot;Value of defined_variable: $defined_variable&quot;\n\n# Using an unset variable\necho &quot;Value of unset_variable: $unset_variable&quot;\n\necho &quot;Script ending...&quot;\n<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">In this Bash script, the command <code class=\"\" data-line=\"\">set -u<\/code> is used to enable the treatment of unset variables as errors. A variable named <code class=\"\" data-line=\"\">defined_variable<\/code> is declared and assigned a value, and its value is echoed to the console. Subsequently, an attempt is made to echo the value of an unset variable, <code class=\"\" data-line=\"\">unset_variable<\/code>. Due to the <code class=\"\" data-line=\"\">set -u<\/code> option, referencing an <strong>unset<\/strong> <strong>variable<\/strong> is treated as an error, which can help catch potential issues related to uninitialized variables.<\/div><\/div><img decoding=\"async\" class=\"aligncenter wp-image-35433 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/3.-Output-image-after-Checking-Unset-Variable-using-set-u-in-Bash.png\" alt=\"Output image after Checking Unset Variable using \u201cset -u\u201d in Bash\" width=\"825\" height=\"225\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/3.-Output-image-after-Checking-Unset-Variable-using-set-u-in-Bash.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/3.-Output-image-after-Checking-Unset-Variable-using-set-u-in-Bash-300x82.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/3.-Output-image-after-Checking-Unset-Variable-using-set-u-in-Bash-768x209.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p style=\"text-align: justify;\">As the &#8216;unset_variable&#8217; was not set previously, the &#8216;set -u&#8217; command triggers an error when the variable is called, as shown above.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>Bash<\/strong> <strong>debugging<\/strong> is one of the most important tools for shell script development and maintenance. It improves the reliability and productivity of shell scripts. Proper utilization of set commands in bash debugging can play an effective role in your code development. This article has tried to discuss multiple examples of set commands in bash debugging. Hope you like it. However, If you have any questions or queries related to this article, feel free to comment below. Thank you!<\/p>\n<h2><span class=\"ez-toc-section\" id=\"People_Also_Ask\"><\/span>People Also Ask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"How_to_set_debug_in_bash_script\"><\/span>How to set debug in bash script?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In Bash scripting, you can set <strong>debug mode <\/strong>by using the<strong> set -x<\/strong> option, which enables debugging output. Here&#8217;s an example of how to set <strong>debug mode <\/strong>in a Bash script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nset -x  # Enable debugging output\n\n# Your script code goes here\n\nset +x  # Disable debugging output\n<\/code><\/pre>\n<p style=\"text-align: justify;\">In this script, set -x is used to activate debugging mode. Once enabled, each command and its arguments will be printed to the standard error output before execution.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_set_debug_mode_in_Linux\"><\/span>How do I set debug mode in Linux?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Debugging in Linux, particularly in a Bash script, often involves using the <strong>set command <\/strong>with the<strong> -x option<\/strong> to enable debugging output. Here&#8217;s how you can set <strong>debug<\/strong> <strong>mode<\/strong> in Linux:<\/p>\n<ol>\n<li style=\"text-align: justify;\"><strong>Command Line Debugging:<\/strong> If you are running a Bash script from the command line and want to enable <strong>debug<\/strong> <strong>mode<\/strong> for that specific execution, you can do it like this:\n<pre><code class=\"language-bash\" data-line=\"\">bash -x your_script.sh<\/code><\/pre>\n<\/li>\n<li style=\"text-align: justify;\"><strong>Debugging Inside the Script:<\/strong> Alternatively, you can include the <code class=\"\" data-line=\"\">set -x<\/code> command directly in your Bash script to enable debugging for the entire script:\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nset -x  # Enable debugging output\n\n# Your script code goes here\n\nset +x  # Disable debugging output\n<\/code><\/pre>\n<p style=\"text-align: justify;\">This way when you execute the script, it will automatically print each command and its arguments before execution.<\/p>\n<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"What_is_the_use_of_set_E_in_Bash\"><\/span>What is the use of set +E in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In Bash, <strong>set +E<\/strong> is used to disable the <strong>ERR trap<\/strong>. The ERR trap is a feature that allows you to execute a command or a series of commands whenever a simple command has a <strong>non-zero exit status<\/strong> (returns an error). By default, the ERR trap is enabled.<\/p>\n<p style=\"text-align: justify;\">When you use <strong>set +E<\/strong>, you are turning off the ERR trap, meaning that the shell will not execute the commands specified in the ERR trap when a command returns a non-zero exit status.<\/p>\n<p style=\"text-align: justify;\">Here&#8217;s an example to illustrate the usage:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Enable ERR trap\nset -e\n\n# ERR trap will be triggered for the following command\necho &quot;This command will trigger the ERR trap&quot; &amp;&amp; false\n\n# Disable ERR trap\nset +E\n\n# ERR trap will not be triggered for the following command\necho &quot;This command will NOT trigger the ERR trap&quot; &amp;&amp; false\n<\/code><\/pre>\n<p style=\"text-align: justify;\">In the example above, the <code class=\"\" data-line=\"\">set -e<\/code> enables the <strong>ERR<\/strong> <strong>trap<\/strong>. The first <strong>echo<\/strong> <strong>command<\/strong> followed by <strong>false<\/strong> triggers the <strong>ERR<\/strong> <strong>trap<\/strong>, causing the script to terminate. After <code class=\"\" data-line=\"\">set +E<\/code>, the second echo command followed by false does not trigger the <strong>ERR<\/strong> <strong>trap<\/strong>, and the script continues to execute despite the <strong>non-zero exit status<\/strong> of the command.<\/p>\n<p><span style=\"font-size: 18pt; color: #003366;\"><strong>Related Articles<\/strong><\/span><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/debug-mode\/\" target=\"_blank\" rel=\"noopener\">How to Activate Debug Mode in Bash Script? [3 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-shellcheck\/\" target=\"_blank\" rel=\"noopener\">How to Debug Bash Script with \u201cShellCheck\u201d Command?<\/a><\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>&lt;&lt; Go Back to <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Debugging&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/\" target=\"_blank\" rel=\"noopener\">Bash Debugging<\/a><\/span> | <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Error Handling and Debugging&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/\"><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><\/span> | <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Scripting Tutorial&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Tutorial<\/a><\/span><\/strong><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;35423&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;How to Debug Bash Script with \u201cset\u201d Command? [3 Cases]&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\">Rate this post<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>The set command in bash is one of the most powerful tools in bash. It has many functionalities such as &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Debug Bash Script with \u201cset\u201d Command? [3 Cases]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#more-35423\" aria-label=\"Read more about How to Debug Bash Script with \u201cset\u201d Command? [3 Cases]\">Read more<\/a><\/p>\n","protected":false},"author":314906,"featured_media":35545,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[194],"class_list":["post-35423","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-bash-debugging","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Debug Bash Script with \u201cset\u201d Command? [3 Cases] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"Bash set command aids debugging with options like -x, printing each command for detailed tracing, and -u treats unset variables as errors.\" \/>\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\/error-handling-and-debugging\/debugging\/bash-set\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Debug Bash Script with \u201cset\u201d Command? [3 Cases] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"Bash set command aids debugging with options like -x, printing each command for detailed tracing, and -u treats unset variables as errors.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/msmshah.miran\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-30T06:53:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-11T07:29:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/bash-set-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Mohammad Shah Miran\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mohammad Shah Miran\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/\"},\"author\":{\"name\":\"Mohammad Shah Miran\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/3d367dace727c53f2b8683eeb23fae77\"},\"headline\":\"How to Debug Bash Script with \u201cset\u201d Command? [3 Cases]\",\"datePublished\":\"2024-01-30T06:53:24+00:00\",\"dateModified\":\"2024-02-11T07:29:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/\"},\"wordCount\":1492,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/bash-set-1.png\",\"keywords\":[\"bash debugging\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/\",\"name\":\"How to Debug Bash Script with \u201cset\u201d Command? [3 Cases] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/bash-set-1.png\",\"datePublished\":\"2024-01-30T06:53:24+00:00\",\"dateModified\":\"2024-02-11T07:29:03+00:00\",\"description\":\"Bash set command aids debugging with options like -x, printing each command for detailed tracing, and -u treats unset variables as errors.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/bash-set-1.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/bash-set-1.png\",\"width\":400,\"height\":400},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/bash-set\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash Scripting Tutorial\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Bash Error Handling and Debugging\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Bash Debugging\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/error-handling-and-debugging\\\/debugging\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to Debug Bash Script with \u201cset\u201d Command? [3 Cases]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"name\":\"LinuxSimply\",\"description\":\"All About Linux\",\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linuxsimply.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\",\"name\":\"LinuxSimply\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"width\":355,\"height\":48,\"caption\":\"LinuxSimply\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/3d367dace727c53f2b8683eeb23fae77\",\"name\":\"Mohammad Shah Miran\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"caption\":\"Mohammad Shah Miran\"},\"description\":\"Hey, I'm Mohammad Shah Miran, previously worked as a VBA and Excel Content Developer at SOFTEKO, and for now working as a Linux Content Developer Executive in LinuxSimply Project. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). As a part of my job, i communicate with Linux operating system, without letting the GUI to intervene and try to pass it to our audience.\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/msmshah.miran\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/shah-miran-2a94a7144\\\/\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/miran\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Debug Bash Script with \u201cset\u201d Command? [3 Cases] - LinuxSimply","description":"Bash set command aids debugging with options like -x, printing each command for detailed tracing, and -u treats unset variables as errors.","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\/error-handling-and-debugging\/debugging\/bash-set\/","og_locale":"en_US","og_type":"article","og_title":"How to Debug Bash Script with \u201cset\u201d Command? [3 Cases] - LinuxSimply","og_description":"Bash set command aids debugging with options like -x, printing each command for detailed tracing, and -u treats unset variables as errors.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/msmshah.miran\/","article_published_time":"2024-01-30T06:53:24+00:00","article_modified_time":"2024-02-11T07:29:03+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/bash-set-1.png","type":"image\/png"}],"author":"Mohammad Shah Miran","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mohammad Shah Miran","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/"},"author":{"name":"Mohammad Shah Miran","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/3d367dace727c53f2b8683eeb23fae77"},"headline":"How to Debug Bash Script with \u201cset\u201d Command? [3 Cases]","datePublished":"2024-01-30T06:53:24+00:00","dateModified":"2024-02-11T07:29:03+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/"},"wordCount":1492,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/bash-set-1.png","keywords":["bash debugging"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/","name":"How to Debug Bash Script with \u201cset\u201d Command? [3 Cases] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/bash-set-1.png","datePublished":"2024-01-30T06:53:24+00:00","dateModified":"2024-02-11T07:29:03+00:00","description":"Bash set command aids debugging with options like -x, printing each command for detailed tracing, and -u treats unset variables as errors.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/bash-set-1.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/bash-set-1.png","width":400,"height":400},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/bash-set\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxsimply.com\/"},{"@type":"ListItem","position":2,"name":"Bash Scripting Tutorial","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/"},{"@type":"ListItem","position":3,"name":"Bash Error Handling and Debugging","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/"},{"@type":"ListItem","position":4,"name":"Bash Debugging","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/debugging\/"},{"@type":"ListItem","position":5,"name":"How to Debug Bash Script with \u201cset\u201d Command? [3 Cases]"}]},{"@type":"WebSite","@id":"https:\/\/linuxsimply.com\/#website","url":"https:\/\/linuxsimply.com\/","name":"LinuxSimply","description":"All About Linux","publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxsimply.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linuxsimply.com\/#organization","name":"LinuxSimply","url":"https:\/\/linuxsimply.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","width":355,"height":48,"caption":"LinuxSimply"},"image":{"@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/3d367dace727c53f2b8683eeb23fae77","name":"Mohammad Shah Miran","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","caption":"Mohammad Shah Miran"},"description":"Hey, I'm Mohammad Shah Miran, previously worked as a VBA and Excel Content Developer at SOFTEKO, and for now working as a Linux Content Developer Executive in LinuxSimply Project. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). As a part of my job, i communicate with Linux operating system, without letting the GUI to intervene and try to pass it to our audience.","sameAs":["https:\/\/www.facebook.com\/msmshah.miran\/","https:\/\/www.linkedin.com\/in\/shah-miran-2a94a7144\/"],"url":"https:\/\/linuxsimply.com\/author\/miran\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/35423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/users\/314906"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=35423"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/35423\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/35545"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=35423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=35423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=35423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}