{"id":2899,"date":"2024-01-17T00:00:43","date_gmt":"2024-01-17T00:00:43","guid":{"rendered":"https:\/\/draculaservers.com\/tutorials\/?p=2899"},"modified":"2024-01-31T19:16:30","modified_gmt":"2024-01-31T19:16:30","slug":"bash-set-e-explained","status":"publish","type":"post","link":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/","title":{"rendered":"Bash\u00a0set -e\u00a0| Explained"},"content":{"rendered":"<div class=\"cl-preview-section\">\n<p id=\"bash-set--e--explained\"><span style=\"font-size: 16px;\">Bash scripting is a powerful tool for automating tasks, and the <\/span><code style=\"font-size: 16px;\">set -e<\/code><span style=\"font-size: 16px;\">\u00a0option plays a crucial role in enhancing the robustness of scripts. This guide will provide a comprehensive explanation of\u00a0<\/span><code style=\"font-size: 16px;\">set -e<\/code><span style=\"font-size: 16px;\">, covering its syntax, working mechanism, and practical examples.<\/span><\/p>\n\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"i.-introduction-to-set--e\"><span id=\"introduction-to-set-e-in-bash\"><span style=\"color: #ff2600;\">Introduction to <code>set -e<\/code> in Bash<\/span><\/span><\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>In Bash scripting,\u00a0<code>set -e<\/code>\u00a0is an option that instructs the script to exit immediately if any command it executes returns a non-zero status. This early exit mechanism is invaluable for improving script reliability.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"b.-importance-of-set--e\"><span id=\"importance-of-set-e\">Importance of <code>set -e<\/code><\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The primary significance of\u00a0<code>set -e<\/code>\u00a0lies in its ability to enhance script reliability. By enforcing an immediate exit upon encountering errors, it helps prevent unintended consequences and ensures that scripts halt execution if critical commands fail.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"c.-impact-on-script-execution\"><span id=\"impact-on-script-execution\">Impact on Script Execution<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>When\u00a0<code>set -e<\/code>\u00a0is in effect, the script will cease execution if any command within it fails. This provides an early indication of issues, preventing further actions that might compound errors.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"ii.-understanding-the-syntax\"><span id=\"understanding-the-syntax\">Understanding the Syntax<\/span><\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To activate the\u00a0<code>set -e<\/code>\u00a0option in a Bash script, include the following line at the beginning of the script:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token shebang important\">#!\/bin\/bash<\/span>\r\n<span class=\"token keyword\">set<\/span> -e\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This ensures that the script will exit if any subsequent command fails.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"iii.-working-mechanism-of-set--e\"><span id=\"working-mechanism-of-set-e\">Working Mechanism of <code>set -e<\/code><\/span><\/h2>\n<p>Let&#8217;s have a look at the working mechanism of the &#8220;set -e&#8221; in Bash scripting.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"a.-exit-on-non-zero-status\"><span id=\"exit-on-non-zero-status\">Exit on Non-Zero Status<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The primary functionality of\u00a0<code>set -e<\/code>\u00a0is to make the script exit if any command it runs returns a non-zero exit status. This is particularly useful for catching errors early in the script execution.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"b.-exceptions-with--operator\"><span id=\"exceptions-with-operator\">Exceptions with <code>||<\/code>\u00a0Operator<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>While\u00a0<code>set -e<\/code>\u00a0provides a robust way to handle errors, there are scenarios where you might want to continue execution despite a command failing. In such cases, the\u00a0<code>||<\/code>\u00a0operator can be used to handle specific commands differently.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token shebang important\">#!\/bin\/bash<\/span>\r\n<span class=\"token keyword\">set<\/span> -e\r\n\r\n<span class=\"token comment\"># Command that can fail without causing the script to exit<\/span>\r\nsome_command <span class=\"token operator\">||<\/span> <span class=\"token boolean\">true<\/span>\r\n\r\n<span class=\"token comment\"># Following commands will still trigger an exit on failure<\/span>\r\nanother_command\r\nyet_another_command\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"iv.-practical-examples\"><span id=\"practical-examples-of-set-e-in-bash\"><span style=\"color: #ff2600;\">Practical Examples of &#8220;set -e&#8221; in Bash<\/span><\/span><\/h2>\n<p>To better understand the working and usage of the &#8220;set -e&#8221; in Bash, let&#8217;s have a look at some practical examples.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"a.-basic-example\"><span id=\"basic-example\">Basic Example<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Let\u2019s consider a simple script without\u00a0<code>set -e<\/code>:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token shebang important\">#!\/bin\/bash<\/span>\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Hello, World!\"<\/span>\r\n\r\n<span class=\"token comment\"># Simulate a failure<\/span>\r\n<span class=\"token function\">ls<\/span> \/nonexistent_directory\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Script continues...\"<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>In this scenario, the script would continue executing even after the\u00a0<code>ls<\/code>\u00a0command fails. Now, let\u2019s add\u00a0<code>set -e<\/code>\u00a0to the script:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token shebang important\">#!\/bin\/bash<\/span>\r\n<span class=\"token keyword\">set<\/span> -e\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Hello, World!\"<\/span>\r\n\r\n<span class=\"token comment\"># Simulate a failure<\/span>\r\n<span class=\"token function\">ls<\/span> \/nonexistent_directory\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Script continues...\"<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>With\u00a0<code>set -e<\/code>, the script would exit immediately after the failed\u00a0<code>ls<\/code>\u00a0command, and \u201cScript continues\u2026\u201d would not be printed.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"b.-advanced-example-with-functions\"><span id=\"advanced-example-with-functions\">Advanced Example with Functions<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Consider a script that includes functions. Without\u00a0<code>set -e<\/code>, the script might proceed with subsequent commands even if a function fails:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token shebang important\">#!\/bin\/bash<\/span>\r\n\r\n<span class=\"token keyword\">function<\/span> critical_function<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Executing critical function...\"<\/span>\r\n    <span class=\"token boolean\">false<\/span> <span class=\"token comment\"># Simulate failure<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Hello, World!\"<\/span>\r\n\r\n<span class=\"token comment\"># Call the critical function<\/span>\r\ncritical_function\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Script continues...\"<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>In this case, \u201cScript continues\u2026\u201d would be printed despite the failure in the\u00a0<code>critical_function<\/code>. Now, let\u2019s add\u00a0<code>set -e<\/code>:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token shebang important\">#!\/bin\/bash<\/span>\r\n<span class=\"token keyword\">set<\/span> -e\r\n\r\n<span class=\"token keyword\">function<\/span> critical_function<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Executing critical function...\"<\/span>\r\n    <span class=\"token boolean\">false<\/span> <span class=\"token comment\"># Simulate failure<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Hello, World!\"<\/span>\r\n\r\n<span class=\"token comment\"># Call the critical function<\/span>\r\ncritical_function\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Script continues...\"<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>With\u00a0<code>set -e<\/code>, the script would exit immediately after the failure in\u00a0<code>critical_function<\/code>.<\/p>\n<h2 id=\"dracula-vps-hosting-service\"><span style=\"color: #ff2600;\">Dracula VPS Hosting Service<\/span><\/h2>\n<p><a href=\"http:\/\/draculaservers.com\"><span style=\"font-weight: 400;\">Dracula Servers<\/span><\/a><span style=\"font-weight: 400;\"> offers high-performance server hosting at entry-level prices. The plans include Linux VPS, Sneaker Servers, Dedicated Servers &amp; turnkey solutions. If you&#8217;re looking for quality self-managed servers with high amounts of RAM and storage, look no further.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Check the plans for yourself by clicking <\/span><a href=\"https:\/\/draculaservers.com\/#pick-plan\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Here<\/span><\/a><span style=\"font-weight: 400;\">!<\/span><\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"iv.-examples\"><span id=\"more-examples-of-bash-set-e-to-practice\">More Examples of Bash &#8220;set -e&#8221; to Practice<\/span><\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Let\u2019s dive into practical examples to illustrate the application of\u00a0<code>set -e<\/code>:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"a.-basic-usage\"><span id=\"basic-usage-of-set-e\">Basic Usage of set -e<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Consider the following simple script (<code>basic_example.sh<\/code>):<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token shebang important\">#!\/bin\/bash<\/span>\r\n<span class=\"token keyword\">set<\/span> -e\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Executing command 1\"<\/span>\r\n<span class=\"token function\">ls<\/span> non_existent_directory\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Command 1 executed successfully\"<\/span>\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Executing command 2\"<\/span>\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Command 2 executed successfully\"<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>In this example, the script attempts to list the contents of a non-existent directory. The second command should not execute due to the\u00a0<code>set -e<\/code>\u00a0option. When you run the script:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">bash<\/span> basic_example.sh\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The output will be:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre><code>Executing command 1\r\nls: cannot access 'non_existent_directory': No such file or directory\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The script terminates after the first command due to the encountered error.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"b.-handling-specific-commands\"><span id=\"handling-specific-commands\">Handling Specific Commands<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Consider a scenario where you want to continue the script even if a specific command fails. In this script (<code>specific_command.sh<\/code>), the\u00a0<code>|| true<\/code>\u00a0construct is used to prevent the script from exiting on that particular error:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token shebang important\">#!\/bin\/bash<\/span>\r\n<span class=\"token keyword\">set<\/span> -e\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Executing command 1\"<\/span>\r\n<span class=\"token function\">ls<\/span> non_existent_directory <span class=\"token operator\">||<\/span> <span class=\"token boolean\">true<\/span>\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Command 1 executed successfully\"<\/span>\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Executing command 2\"<\/span>\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Command 2 executed successfully\"<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>When you run the script:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">bash<\/span> specific_command.sh\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The output will be:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre><code>Executing command 1\r\nls: cannot access 'non_existent_directory': No such file or directory\r\nCommand 1 executed successfully\r\nExecuting command 2\r\nCommand 2 executed successfully\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The script continues to execute after the failed command.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"c.-combining-with-conditional-statements\"><span id=\"combining-with-conditional-statements\">Combining with Conditional Statements<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>In this script (<code>conditional_example.sh<\/code>),\u00a0<code>set -e<\/code>\u00a0is combined with conditional statements:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token shebang important\">#!\/bin\/bash<\/span>\r\n<span class=\"token keyword\">set<\/span> -e\r\n\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Executing command 1\"<\/span>\r\n<span class=\"token function\">ls<\/span> non_existent_directory\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Command 1 executed successfully\"<\/span>\r\n\r\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">[<\/span> -e <span class=\"token string\">\"existing_file.txt\"<\/span> <span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">then<\/span>\r\n    <span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Executing command 2\"<\/span>\r\n    <span class=\"token function\">cat<\/span> existing_file.txt\r\n    <span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Command 2 executed successfully\"<\/span>\r\n<span class=\"token keyword\">fi<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>When you run the script:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">bash<\/span> conditional_example.sh\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The output will be:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre><code>Executing command 1\r\nls: cannot access 'non_existent_directory': No such file or directory\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The script terminates after the first command due to the encountered error. Feel free to modify these examples to suit your specific use cases and explore the behavior of\u00a0<code>set -e<\/code>\u00a0in different scenarios.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"v.-conclusion\"><span id=\"conclusion\">Conclusion<\/span><\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>In conclusion,\u00a0<code>set -e<\/code> is a valuable tool for Bash scriptwriters, offering a mechanism to enhance script reliability by ensuring an immediate exit on encountering errors. Understanding its syntax, working mechanism, and practical implementation through examples equips scriptwriters with a powerful tool to create more robust and error-resistant Bash scripts.<\/p>\n<p><a href=\"https:\/\/draculaservers.com\/tutorials\/\" target=\"_blank\" rel=\"noopener\">Read More Linux Guides Here!<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bash scripting is a powerful tool for automating tasks, and the set -e\u00a0option plays a crucial role in enhancing the robustness of scripts. This guide will provide a comprehensive explanation of\u00a0set -e, covering its syntax, working mechanism, and practical examples. Introduction to set -e in Bash In Bash scripting,\u00a0set -e\u00a0is an option that instructs the [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":2901,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61,172],"tags":[228,230,229,231],"class_list":["post-2899","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands","category-linux-tutorials","tag-bash-scripting-tutorial","tag-bash-scripting-tutorials","tag-bash-set-e-explained","tag-linux-system-programming"],"blocksy_meta":[],"featured_image_urls_v2":{"full":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20.png",1280,720,false],"thumbnail":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20-150x150.png",150,150,true],"medium":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20-300x169.png",300,169,true],"medium_large":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20-768x432.png",768,432,true],"large":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20-1024x576.png",1024,576,true],"1536x1536":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20.png",1280,720,false],"2048x2048":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20.png",1280,720,false],"pk-small":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20-80x80.png",80,80,true],"pk-thumbnail":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20-300x225.png",300,225,true]},"post_excerpt_stackable_v2":"<p>Bash scripting is a powerful tool for automating tasks, and the set -e\u00a0option plays a crucial role in enhancing the robustness of scripts. This guide will provide a comprehensive explanation of\u00a0set -e, covering its syntax, working mechanism, and practical examples. Introduction to set -e in Bash In Bash scripting,\u00a0set -e\u00a0is an option that instructs the script to exit immediately if any command it executes returns a non-zero status. This early exit mechanism is invaluable for improving script reliability. Importance of set -e The primary significance of\u00a0set -e\u00a0lies in its ability to enhance script reliability. By enforcing an immediate exit upon&hellip;<\/p>\n","category_list_v2":"<a href=\"https:\/\/draculaservers.com\/tutorials\/category\/linux-commands\/\" rel=\"category tag\">Linux Commands<\/a>, <a href=\"https:\/\/draculaservers.com\/tutorials\/category\/linux-tutorials\/\" rel=\"category tag\">Linux Tutorials<\/a>","author_info_v2":{"name":"Abdul Mannan","url":"https:\/\/draculaservers.com\/tutorials\/author\/abdul-mannan-tbgmail-com\/"},"comments_num_v2":"0 comments","yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Bash\u00a0set -e\u00a0| Explained - Dracula Servers Tutorials<\/title>\n<meta name=\"description\" content=\"The purpose of Bash set -e is to make the script exit immediately if any command it runs exits with a non-zero status, signaling an error.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bash\u00a0set -e\u00a0| Explained - Dracula Servers Tutorials\" \/>\n<meta property=\"og:description\" content=\"The purpose of Bash set -e is to make the script exit immediately if any command it runs exits with a non-zero status, signaling an error.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/\" \/>\n<meta property=\"og:site_name\" content=\"Dracula Servers Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-17T00:00:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-31T19:16:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Abdul Mannan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abdul Mannan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/\"},\"author\":{\"name\":\"Abdul Mannan\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/ac89d0281f4fb596bfaa0bc1e746c8a6\"},\"headline\":\"Bash\u00a0set -e\u00a0| Explained\",\"datePublished\":\"2024-01-17T00:00:43+00:00\",\"dateModified\":\"2024-01-31T19:16:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/\"},\"wordCount\":691,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/What-20.png\",\"keywords\":[\"Bash Scripting Tutorial\",\"Bash Scripting Tutorials\",\"Bash set e explained\",\"Linux System Programming\"],\"articleSection\":[\"Linux Commands\",\"Linux Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/\",\"name\":\"Bash\u00a0set -e\u00a0| Explained - Dracula Servers Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/What-20.png\",\"datePublished\":\"2024-01-17T00:00:43+00:00\",\"dateModified\":\"2024-01-31T19:16:30+00:00\",\"description\":\"The purpose of Bash set -e is to make the script exit immediately if any command it runs exits with a non-zero status, signaling an error.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/#primaryimage\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/What-20.png\",\"contentUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/What-20.png\",\"width\":1280,\"height\":720,\"caption\":\"Bash\u00a0set -e\u00a0| Explained\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/bash-set-e-explained\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash\u00a0set -e\u00a0| Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/\",\"name\":\"Dracula Servers Tutorials\",\"description\":\"Dedicated Servers\",\"publisher\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#organization\",\"name\":\"Dracula Servers\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/dracula_full_logo_smaller.png\",\"contentUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/dracula_full_logo_smaller.png\",\"width\":1625,\"height\":200,\"caption\":\"Dracula Servers\"},\"image\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/ac89d0281f4fb596bfaa0bc1e746c8a6\",\"name\":\"Abdul Mannan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g\",\"caption\":\"Abdul Mannan\"},\"description\":\"An individual trying to decipher the enigmas of technology by the sheer driving force of curiosity. Interested in learning new skills and being better at those skills than the lot.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bash\u00a0set -e\u00a0| Explained - Dracula Servers Tutorials","description":"The purpose of Bash set -e is to make the script exit immediately if any command it runs exits with a non-zero status, signaling an error.","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:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/","og_locale":"en_US","og_type":"article","og_title":"Bash\u00a0set -e\u00a0| Explained - Dracula Servers Tutorials","og_description":"The purpose of Bash set -e is to make the script exit immediately if any command it runs exits with a non-zero status, signaling an error.","og_url":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/","og_site_name":"Dracula Servers Tutorials","article_published_time":"2024-01-17T00:00:43+00:00","article_modified_time":"2024-01-31T19:16:30+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20.png","type":"image\/png"}],"author":"Abdul Mannan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Abdul Mannan","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/#article","isPartOf":{"@id":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/"},"author":{"name":"Abdul Mannan","@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/person\/ac89d0281f4fb596bfaa0bc1e746c8a6"},"headline":"Bash\u00a0set -e\u00a0| Explained","datePublished":"2024-01-17T00:00:43+00:00","dateModified":"2024-01-31T19:16:30+00:00","mainEntityOfPage":{"@id":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/"},"wordCount":691,"commentCount":0,"publisher":{"@id":"https:\/\/draculaservers.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/#primaryimage"},"thumbnailUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20.png","keywords":["Bash Scripting Tutorial","Bash Scripting Tutorials","Bash set e explained","Linux System Programming"],"articleSection":["Linux Commands","Linux Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/","url":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/","name":"Bash\u00a0set -e\u00a0| Explained - Dracula Servers Tutorials","isPartOf":{"@id":"https:\/\/draculaservers.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/#primaryimage"},"image":{"@id":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/#primaryimage"},"thumbnailUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20.png","datePublished":"2024-01-17T00:00:43+00:00","dateModified":"2024-01-31T19:16:30+00:00","description":"The purpose of Bash set -e is to make the script exit immediately if any command it runs exits with a non-zero status, signaling an error.","breadcrumb":{"@id":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/#primaryimage","url":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20.png","contentUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/01\/What-20.png","width":1280,"height":720,"caption":"Bash\u00a0set -e\u00a0| Explained"},{"@type":"BreadcrumbList","@id":"https:\/\/draculaservers.com\/tutorials\/bash-set-e-explained\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/draculaservers.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Bash\u00a0set -e\u00a0| Explained"}]},{"@type":"WebSite","@id":"https:\/\/draculaservers.com\/tutorials\/#website","url":"https:\/\/draculaservers.com\/tutorials\/","name":"Dracula Servers Tutorials","description":"Dedicated Servers","publisher":{"@id":"https:\/\/draculaservers.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/draculaservers.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/draculaservers.com\/tutorials\/#organization","name":"Dracula Servers","url":"https:\/\/draculaservers.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2016\/06\/dracula_full_logo_smaller.png","contentUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2016\/06\/dracula_full_logo_smaller.png","width":1625,"height":200,"caption":"Dracula Servers"},"image":{"@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/person\/ac89d0281f4fb596bfaa0bc1e746c8a6","name":"Abdul Mannan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g","caption":"Abdul Mannan"},"description":"An individual trying to decipher the enigmas of technology by the sheer driving force of curiosity. Interested in learning new skills and being better at those skills than the lot."}]}},"_links":{"self":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts\/2899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/comments?post=2899"}],"version-history":[{"count":4,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts\/2899\/revisions"}],"predecessor-version":[{"id":2904,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts\/2899\/revisions\/2904"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/media\/2901"}],"wp:attachment":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/media?parent=2899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/categories?post=2899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/tags?post=2899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}