{"id":36406,"date":"2024-02-08T10:31:32","date_gmt":"2024-02-08T10:31:32","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=36406"},"modified":"2024-05-09T11:54:05","modified_gmt":"2024-05-09T11:54:05","slug":"bash-if-command-fails","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/","title":{"rendered":"Check If Bash Command Fail or Succeed [Exit If Fail]"},"content":{"rendered":"<p style=\"text-align: justify;\">Exit status is the performance indicator that incorporates checking if a command fails or succeeds in Bash. Whether you are developing complex scripts or automating tasks, it is essential to know how to check a command\u2019s success or failure as well as how to exit the script if a command fails or error occurs.<\/p>\n<p style=\"text-align: justify;\">The following article will demonstrate <strong>2<\/strong> methods to check if a command fails or succeeds and <strong>4<\/strong> methods to exit if a command fails in Bash. Let\u2019s delve into it!<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Practice-Files_Bash-Check-If-Command-Fails-Or-Succeeds.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 Check If a Command Fails or Succeeds in Bash<\/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\/conditional-statements\/if\/if-command-fails\/#What_is_an_Exit_Code_in_Bash\" >What is an Exit Code 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\/conditional-statements\/if\/if-command-fails\/#2_Ways_to_Check_If_a_Command_Fails_or_Succeeds_in_Bash\" >2 Ways to Check If a Command Fails or Succeeds 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-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#1_Checking_Exit_Status_with_Variable\" >1. Checking Exit Status with $? Variable<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#2_Checking_Exit_Status_Using_and_Operators\" >2. Checking Exit Status Using &amp;&amp; and || Operators<\/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\/conditional-statements\/if\/if-command-fails\/#How_to_Exit_If_a_Command_Fails_in_Bash\" >How to Exit If a Command Fails 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-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#1_Using_%E2%80%9Cexit%E2%80%9D_Command\" >1. Using \u201cexit\u201d Command<\/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\/conditional-statements\/if\/if-command-fails\/#2_Using_%E2%80%9Cset_-e%E2%80%9D_Option\" >2. Using \u201cset -e\u201d Option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#3_Using_%E2%80%9Cset_-eo_pipefail%E2%80%9D_Option\" >3. Using \u201cset -eo pipefail\u201d Option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#4_Using_%E2%80%98set_-u_Option\" >4. Using \u2018set -u\u2019 Option<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#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-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#How_to_check_if_a_command_fails_in_Bash\" >How to check if a command fails in Bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#How_to_check_if_a_Bash_command_succeeds\" >How to check if a Bash command succeeds?<\/a><\/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\/conditional-statements\/if\/if-command-fails\/#Can_I_immediately_exit_a_script_if_any_command_fails_in_bash\" >Can I immediately exit a script if any command fails in bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#Does_a_Bash_script_fail_if_a_command_fails\" >Does a Bash script fail if a command fails?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#How_to_exit_1_if_command_fails_in_Bash\" >How to exit 1 if command fails in Bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#Can_I_check_the_exit_status_of_a_command_in_a_function\" >Can I check the exit status of a command in a function?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#Is_there_a_shorthand_method_for_checking_command_failure_in_Bash\" >Is there a shorthand method for checking command failure in Bash?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"What_is_an_Exit_Code_in_Bash\"><\/span>What is an Exit Code in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">The exit code is an integer value (ranging from <strong>0 to 255<\/strong>) returned by a command after a complete execution. It indicates whether a command executed successfully or encountered any errors. Every command executed in Bash returns an exit code or status of either zero (0) or non-zero value (any value greater than 0) where <strong>0 signifies success<\/strong> and <strong>any<\/strong> <strong>non-zero value indicates failure<\/strong>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"2_Ways_to_Check_If_a_Command_Fails_or_Succeeds_in_Bash\"><\/span>2 Ways to Check If a Command Fails or Succeeds in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In the following section, I\u2019ll explain 2 methods such as using the special variable <strong>$?<\/strong> and using <strong>&amp;&amp;<\/strong> and <strong>||<\/strong> operators to examine the exit status and check if a command fails or succeeds in Bash.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Checking_Exit_Status_with_Variable\"><\/span>1. Checking Exit Status with $? Variable<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In Bash, <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/dollar-sign\/\" target=\"_blank\" rel=\"noopener\"><strong>$?<\/strong><\/a> is a special variable that stores the exit status of the last executed command. To check if a command succeeds or not, simply verify the exit status of the command using <code class=\"\" data-line=\"\">$?<\/code>.<\/p>\n<p>Here\u2019s a Bash script to check if a command fails or succeeds using the <code class=\"\" data-line=\"\">$?<\/code> special variable:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#Checking for successful execution\nls -l \/home\/nadiba\/Documents\nif [ $? -eq 0 ]; then\n\u00a0\u00a0\u00a0 echo &quot;Successful execution of ls command&quot;\nfi\n\n#Checking for failed execution\nmkdir \/home\/nadiba\/distro\nif [ $? -ne 0 ]; then\n\u00a0\u00a0\u00a0 echo &quot;mkdir command failed&quot;\nfi<\/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 the script, <code class=\"\" data-line=\"\">if [ $? -eq 0 ]<\/code> checks the exit status of the recently executed <a href=\"https:\/\/linuxsimply.com\/ls-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>ls command<\/strong><\/a>. If the exit status equals zero, it means the ls command executed successfully. In the next part, <code class=\"\" data-line=\"\">if [ $? -ne 0 ]<\/code> checks if the exit status of the last executed <a href=\"https:\/\/linuxsimply.com\/mkdir-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>mkdir command<\/strong><\/a> is not equal to zero. If so, it means the command failed.<\/p>\n<\/div><\/div>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-36425\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Checking-if-a-command-succeeds-or-fails-using-a-special-variable.png\" alt=\"Checking if a command succeeds or fails using a special variable in Bash\" width=\"825\" height=\"236\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Checking-if-a-command-succeeds-or-fails-using-a-special-variable.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Checking-if-a-command-succeeds-or-fails-using-a-special-variable-300x86.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Checking-if-a-command-succeeds-or-fails-using-a-special-variable-768x220.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p style=\"text-align: justify;\">In the above image, the <strong>ls <\/strong>command executed successfully and displayed detailed information about the files and directories in my system&#8217;s specified location &#8216;\/home\/nadiba\/Documents&#8217;. However, the <strong>mkdir<\/strong> command failed as the specified directory already exists in &#8216;\/home\/nadiba\/distro&#8217;.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Checking_Exit_Status_Using_and_Operators\"><\/span>2. Checking Exit Status Using &amp;&amp; and || Operators<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To check if a command fails or succeeds, use the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/logical-operators\/and\/\" target=\"_blank\" rel=\"noopener\"><strong>&amp;&amp; (logical AND)<\/strong><\/a> and <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/operator\/logical-operators\/or\/\" target=\"_blank\" rel=\"noopener\"><strong>|| (logical OR)<\/strong><\/a> operators and conditionally execute different commands based on the output. The <code class=\"\" data-line=\"\">&amp;&amp;<\/code> operator executes only when the preceding command returns a zero exit status i.e. succeeds. On the contrary, the <code class=\"\" data-line=\"\">||<\/code> operator executes only when the preceding command returns a non-zero exit status i.e. fails.<\/p>\n<p>Check out the following script to check if a command fails or succeeds using the <code class=\"\" data-line=\"\">&amp;&amp;<\/code> and <code class=\"\" data-line=\"\">||<\/code> operators:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#Checking for successful execution\nls -l \/home\/nadiba\/Downloads &amp;&amp; echo &quot;ls command executed successfully&quot;\n\n#Checking for failed execution\nrm example.txt || echo &quot;File doesn&#039;t exist. rm command execution failed.&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">In this script, if the <strong>ls<\/strong> command succeeds, the subsequent <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/echo-command\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a> will be executed using the <strong>&amp;&amp; <\/strong>operator. For the next part, if the <a href=\"https:\/\/linuxsimply.com\/rm-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>rm command<\/strong><\/a> fails, the subsequent echo command will be executed using the <strong>||<\/strong> operator.<\/p>\n<\/div><\/div>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-36426\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Checking-if-a-command-succeeds-or-fails-using-logical-AND-and-logical-OR-operator.png\" alt=\"Checking if a command succeeds or fails using logical AND (&amp;&amp;) and logical OR (||) operator in Bash\" width=\"825\" height=\"259\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Checking-if-a-command-succeeds-or-fails-using-logical-AND-and-logical-OR-operator.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Checking-if-a-command-succeeds-or-fails-using-logical-AND-and-logical-OR-operator-300x94.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Checking-if-a-command-succeeds-or-fails-using-logical-AND-and-logical-OR-operator-768x241.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p style=\"text-align: justify;\">As you can see in the image the <strong>ls<\/strong> command executed successfully but the <strong>rm<\/strong> command failed as the file didn\u2019t exist in the system.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Exit_If_a_Command_Fails_in_Bash\"><\/span>How to Exit If a Command Fails in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Bash offers several methods to exit when a command fails such as using <strong>exit<\/strong> command, <strong>set -e<\/strong> option, <strong>set -eo pipefail<\/strong> option and <strong>set -u<\/strong> option. In the following section, I\u2019ll explain how to use these methods to exit when a command fails in Bash.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Using_%E2%80%9Cexit%E2%80%9D_Command\"><\/span>1. Using \u201cexit\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Calling the <a href=\"https:\/\/linuxsimply.com\/exit-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>exit command<\/strong><\/a> with an exit code indicates immediate termination of the script\u2019s execution. To exit if a command fails, use the exit code 1 with the <strong>exit<\/strong> command like the following script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#Command1\nls -l \/home\/Documents\nif [ $? -ne 0 ]; then\n\u00a0\u00a0\u00a0 echo &quot;ls command failed. Exit the script&quot;\n\u00a0\u00a0\u00a0 exit 1\nfi\n\n#Command2\nmkdir \/home\/distro\/ubuntu\nif [ $? -ne 0 ]; then\n\u00a0\u00a0\u00a0 echo &quot;mkdir command failed. Exit the script&quot;\n\u00a0\u00a0\u00a0 exit 1\nfi<\/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;\">Here, <code class=\"\" data-line=\"\">if [ $? -ne 0 ]<\/code> checks the exit status of the recently executed <strong>ls<\/strong> command. If the exit status is not equal to zero, the script exits using <code class=\"\" data-line=\"\">exit 1<\/code> without checking the further command.<\/p>\n<\/div><\/div>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-36427\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-exit-command-with-exit-code-if-command-fails.png\" alt=\"Exit script using the exit command with exit code 1 if a command fails in Bash\" width=\"825\" height=\"136\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-exit-command-with-exit-code-if-command-fails.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-exit-command-with-exit-code-if-command-fails-300x49.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-exit-command-with-exit-code-if-command-fails-768x127.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p style=\"text-align: justify;\">As you can see from the image the <strong>ls<\/strong> command failed and so the script exits immediately without even executing the next command.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Using_%E2%80%9Cset_-e%E2%80%9D_Option\"><\/span>2. Using \u201cset -e\u201d Option<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">set -e<\/code>\u00a0option instructs a Bash script to terminate as soon as a command fails, i.e., returns a non-zero exit status.<\/p>\n<p style=\"text-align: justify;\">To check how to exit if a command fails using <strong>set -e<\/strong> option, check out the following Bash script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nset -e\n\nmkdir \/home\/example.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<p>Here, <code class=\"\" data-line=\"\">set -e<\/code> ensures that the script exits immediately if the <strong>mkdir<\/strong> command fails to execute.<\/p>\n<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-36428\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-e-option-if-command-fails.png\" alt=\"Exit script using set -e option if a command fails in Bash\" width=\"825\" height=\"115\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-e-option-if-command-fails.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-e-option-if-command-fails-300x42.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-e-option-if-command-fails-768x107.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p style=\"text-align: justify;\">This images states that the <strong>mkdir<\/strong> command failed to create the directory &#8216;example.txt&#8217; which leads the script to exit immediately.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Using_%E2%80%9Cset_-eo_pipefail%E2%80%9D_Option\"><\/span>3. Using \u201cset -eo pipefail\u201d Option<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">When a script contains multiple commands using piped statements, the <code class=\"\" data-line=\"\">set -eo pipefail<\/code> option helps the script to exit if any command in the pipeline fails, not just the most recent one.<\/p>\n<p style=\"text-align: justify;\">Following is a Bash script that exits using <strong>set -eo pipefail<\/strong> option when a command fails:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nset -eo pipefail\n\necho &quot;The command runs&quot;\n#&#039;find&#039; command: Generates a list of files in \/path\/to\/directory (including hidden ones)\n#&#039;sort&#039; command: Sorts the list of files in reverse order\n#&#039;grep&#039; command: Filters out lines that contain the word &quot;Linux&quot;\nfind \/home\/nadiba\/distro -type f | sort -r | grep -v &quot;Linux&quot;\necho &quot;The command doesn&#039;t run&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">Here, The <code class=\"\" data-line=\"\">set -eo pipefail<\/code> ensures that the script exits as soon as any command either \u201cfind\u201d, \u201csort\u201d or \u201cgrep\u201d inside the pipeline fails.<\/p>\n<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-36429\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-eo-pipefail-option-if-a-command-fails.png\" alt=\"Exit script using set -eo pipefail option if a command fails in Bash\" width=\"825\" height=\"147\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-eo-pipefail-option-if-a-command-fails.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-eo-pipefail-option-if-a-command-fails-300x53.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-eo-pipefail-option-if-a-command-fails-768x137.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p style=\"text-align: justify;\">In the above image, you can see that the <strong>find<\/strong> command failed to list the files in &#8216;\/home\/nadiba\/distro&#8217; which causes the script to exit immediately without even executing the last <strong>echo<\/strong> command.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Using_%E2%80%98set_-u_Option\"><\/span>4. Using \u2018set -u\u2019 Option<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">set -u<\/code> option is generally used at the start of a script where the <code class=\"\" data-line=\"\">-u<\/code> option stands for <strong>nounset<\/strong>. When enabled, the &#8220;set -u&#8221; option terminates the script if there is any undefined or uninitialized variable.<\/p>\n<p style=\"text-align: justify;\">Here\u2019s a Bash script showing how to exit using <strong>set -u<\/strong> when a command fails:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#nounset\nset -u\n\necho &quot;The command runs&quot;\necho $non_existing_variable\necho &quot;The command doesn&#039;t run&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">Here, <code class=\"\" data-line=\"\">set -u<\/code> treats the unset or uninitialized variable <strong>$non_existing_variable<\/strong> as an error and causes the script to exit immediately.<\/p>\n<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-36430\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-u-option-when-found-an-uninitialized-variable.png\" alt=\"Exit script using set -u option when found an uninitialized variable in Bash\" width=\"825\" height=\"124\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-u-option-when-found-an-uninitialized-variable.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-u-option-when-found-an-uninitialized-variable-300x45.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Exit-script-using-set-u-option-when-found-an-uninitialized-variable-768x115.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p style=\"text-align: justify;\">From the image, you can see that the script referenced the unset variable as an <strong>unbound variable<\/strong> error which instructs the script to exit immediately.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>So far, this article described different methods to check if a command fails or succeeds in Bash as well as to exit if a command fails in Bash. To conclude<span style=\"font-size: inherit; text-align: justify;\">, having a good knowledge of these methods ensures the reliability and robustness of Bash scripts. In fact, verifying the exit status of a command really helps in error handling and automating tasks based on different command executions.<\/span><\/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_check_if_a_command_fails_in_Bash\"><\/span>How to check if a command fails in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To check if a command fails in Bash, use the special variable <code class=\"\" data-line=\"\">$?<\/code> inside conditional statements. To do this, use the <code class=\"\" data-line=\"\">if [ $? -ne 0 ]<\/code> syntax to check if the exit status of the command is not equal to zero. Usually, a command that fails to execute will return a non-zero output. If the condition is true, it means that the command failed to execute.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_check_if_a_Bash_command_succeeds\"><\/span>How to check if a Bash command succeeds?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">To check if a Bash command succeeds, use the syntax <code class=\"\" data-line=\"\">if [ $? -eq 0 ]<\/code> that determines if the exit status of the command is equal to zero. A successful execution always returns a zero exit status. So, if the condition evaluates to true, it indicates the command executed successfully.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_immediately_exit_a_script_if_any_command_fails_in_bash\"><\/span>Can I immediately exit a script if any command fails in bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><b>Yes<\/b><span style=\"font-weight: 400;\">, you can immediately exit a script if any command fails in Bash by enabling the <code class=\"\" data-line=\"\">set -e<\/code> option at the start of the script. The &#8216;set -e&#8217; option enables the <\/span><b>errexit <\/b><span style=\"font-weight: 400;\">mode, which instructs the Bash script to terminate immediately when a command exits with a non-zero exit status i.e. fails or an error occurs.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Does_a_Bash_script_fail_if_a_command_fails\"><\/span>Does a Bash script fail if a command fails?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><strong>No<\/strong>, by default a Bash script does not fail if a command fails. It continues executing subsequent commands without caring about earlier commands unless you set or enable certain options.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_exit_1_if_command_fails_in_Bash\"><\/span>How to exit 1 if command fails in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To exit 1 if command fails in Bash, first explicitly check the exit status of the command using <code class=\"\" data-line=\"\">$?<\/code> variable and then use the <code class=\"\" data-line=\"\">exit<\/code> command with the exit code <strong>1<\/strong> if the command fails. For example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#Command1\nls -l \/path\/to\/directory\nif [ $? -ne 0 ]; then\n\u00a0\u00a0\u00a0 echo &quot;ls command failed. Exit the script&quot;\n\u00a0\u00a0\u00a0 exit 1\nfi\n\n#Command2\nmkdir \/path\/to\/directory\nif [ $? -ne 0 ]; then\n\u00a0\u00a0\u00a0 echo &quot;mkdir command failed. Exit the script&quot;\n\u00a0\u00a0\u00a0 exit 1\nfi<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_check_the_exit_status_of_a_command_in_a_function\"><\/span>Can I check the exit status of a command in a function?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><strong>Yes<\/strong>, you can check the exit status of a command in a function using the special variable <code class=\"\" data-line=\"\">$?<\/code>. For example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#Defining a function\ncommand_check() {\n\u00a0\u00a0\u00a0 #Command execution\n\u00a0\u00a0\u00a0 ls -l \/path\/to\/directory\n\u00a0\u00a0\u00a0 #Checking the exit status of the command\n\u00a0\u00a0\u00a0 if [ $? -eq 0 ]; then\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &quot;Command succeeds&quot;\n\u00a0\u00a0\u00a0 else\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &quot;Command fails&quot;\n\u00a0\u00a0\u00a0 fi\n}\n\n#Calling the function\ncommand_check<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Is_there_a_shorthand_method_for_checking_command_failure_in_Bash\"><\/span>Is there a shorthand method for checking command failure in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><strong>Yes<\/strong>, you can use the logical AND (&amp;&amp;) and logical OR (||) operators as a shorthand method\u00a0 to check for command failure in Bash. For example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nrm non_existent_file.txt &amp;&amp; echo &quot;The file removed successfully&quot; || echo &quot;File removal failed&quot;<\/code><\/pre>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"How to check if a command fails in Bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To check if a command fails in Bash, use the special variable $? inside conditional statements. To do this, use the if [ $? -ne 0 ] syntax to check if the exit status of the command is not equal to zero. Usually, a command that fails to execute will return a non-zero output. If the condition is true, it means that the command failed to execute.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"How to check if a Bash command succeeds?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To check if a Bash command succeeds, use the syntax if [ $? -eq 0 ] that determines if the exit status of the command is equal to zero. A successful execution always returns a zero exit status. So, if the condition evaluates to true, it indicates the command executed successfully.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Can I immediately exit a script if any command fails in bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Yes, you can immediately exit a script if any command fails in Bash by enabling the set -e option at the start of the script. The 'set -e' option enables the errexit mode, which instructs the Bash script to terminate immediately when a command exits with a non-zero exit status i.e. fails or an error occurs.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Does a Bash script fail if a command fails?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"No, by default a Bash script does not fail if a command fails. It continues executing subsequent commands without caring about earlier commands unless you set or enable certain options.\"\n    }\n  }]\n}\n<\/script><br \/>\n<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\/conditional-statements\/if\/if-options\/\" target=\"_blank\" rel=\"noopener\">Mastering 10 Essential Options of If Statement in Bash<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-true-false\/\" target=\"_blank\" rel=\"noopener\">How to Check a Boolean If True or False in Bash [Easy Guide]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-test\/\" target=\"_blank\" rel=\"noopener\">Bash Test Operations in \u2018If\u2019 Statement<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-empty-or-not\/\" target=\"_blank\" rel=\"noopener\">Check If a Variable is Empty\/Null or Not in Bash [5 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/set-variable-if-not\/\" target=\"_blank\" rel=\"noopener\">Check If a Variable is Set or Not in Bash [4 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/environment-variable-exists\/\" target=\"_blank\" rel=\"noopener\">Check If Environment Variable Exists in Bash [6 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/modulo-if\/\" target=\"_blank\" rel=\"noopener\">Bash Modulo Operations in &#8220;If&#8221; Statement [4 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/or-and-not-in-if\/\" target=\"_blank\" rel=\"noopener\">How to Use &#8220;OR&#8221;, &#8220;AND&#8221;, &#8220;NOT&#8221; in Bash If Statement [7 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/multiple-if-conditions\/\" target=\"_blank\" rel=\"noopener\">Evaluate Multiple Conditions in Bash \u201cIf\u201d Statement [2 Ways]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/double-brackets\/\" target=\"_blank\" rel=\"noopener\">Using Double Square Brackets \u201c[[ ]]\u201d in If Statement in Bash<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/check-if-file-exists\/\" target=\"_blank\" rel=\"noopener\">6 Ways to Check If a File Exists or Not in Bash<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/check-if-file-is-empty\/\" target=\"_blank\" rel=\"noopener\">How to Check If a File is Empty in Bash [6 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/check-if-directory-exists\/\" target=\"_blank\" rel=\"noopener\">7 Ways to Check If Directory Exists or Not in Bash<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/negate-if\/\" target=\"_blank\" rel=\"noopener\">Negate an &#8220;If&#8221; Condition in Bash [4 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-one-line\/\" target=\"_blank\" rel=\"noopener\">How to Write If Statement in One Line? [2 Easy Ways]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-loop\/\" target=\"_blank\" rel=\"noopener\">Different Loops with If Statements in Bash [5 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/flags\/\" target=\"_blank\" rel=\"noopener\">How to Use Flags in Bash If Condition? [With Example]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/compare-dates\/\" target=\"_blank\" rel=\"noopener\">Learn to Compare Dates in Bash [4 Examples]<\/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;If Statement in Bash&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\/conditional-statements\/if\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/\" target=\"_blank\" rel=\"noopener\">If Statement in Bash<\/a><\/span> | <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Conditional Statements&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\/conditional-statements\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/\" target=\"_blank\" rel=\"noopener\">Bash Conditional Statements<\/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;36406&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;Check If Bash Command Fail or Succeed [Exit If Fail]&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>Exit status is the performance indicator that incorporates checking if a command fails or succeeds in Bash. Whether you are &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Check If Bash Command Fail or Succeed [Exit If Fail]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#more-36406\" aria-label=\"Read more about Check If Bash Command Fail or Succeed [Exit If Fail]\">Read more<\/a><\/p>\n","protected":false},"author":314905,"featured_media":36417,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[166],"class_list":["post-36406","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-if-statement","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>Check If Bash Command Fail or Succeed [Exit If Fail] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"Explore the methods to check if command fails or succeeds and learn how to efficiently handle command failures in Bash 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\/conditional-statements\/if\/if-command-fails\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Check If Bash Command Fail or Succeed [Exit If Fail] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"Explore the methods to check if command fails or succeeds and learn how to efficiently handle command failures in Bash scripting.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/\" \/>\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=\"2024-02-08T10:31:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-09T11:54:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Feature-image-Bash-check-if-command-fails-or-succeeds.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=\"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=\"9 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\\\/conditional-statements\\\/if\\\/if-command-fails\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/\"},\"author\":{\"name\":\"Nadiba Rahman\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/69b717a03a5d9dc48e683aaffe22d33f\"},\"headline\":\"Check If Bash Command Fail or Succeed [Exit If Fail]\",\"datePublished\":\"2024-02-08T10:31:32+00:00\",\"dateModified\":\"2024-05-09T11:54:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/\"},\"wordCount\":1660,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/Feature-image-Bash-check-if-command-fails-or-succeeds.png\",\"keywords\":[\"if statement\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/\",\"name\":\"Check If Bash Command Fail or Succeed [Exit If Fail] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/Feature-image-Bash-check-if-command-fails-or-succeeds.png\",\"datePublished\":\"2024-02-08T10:31:32+00:00\",\"dateModified\":\"2024-05-09T11:54:05+00:00\",\"description\":\"Explore the methods to check if command fails or succeeds and learn how to efficiently handle command failures in Bash scripting.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/Feature-image-Bash-check-if-command-fails-or-succeeds.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/Feature-image-Bash-check-if-command-fails-or-succeeds.png\",\"width\":400,\"height\":400,\"caption\":\"Feature image-Bash check if command fails or succeeds\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/if-command-fails\\\/#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 Conditional Statements\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"If Statement in Bash\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/conditional-statements\\\/if\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Check If Bash Command Fail or Succeed [Exit If Fail]\"}]},{\"@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":"Check If Bash Command Fail or Succeed [Exit If Fail] - LinuxSimply","description":"Explore the methods to check if command fails or succeeds and learn how to efficiently handle command failures in Bash 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\/conditional-statements\/if\/if-command-fails\/","og_locale":"en_US","og_type":"article","og_title":"Check If Bash Command Fail or Succeed [Exit If Fail] - LinuxSimply","og_description":"Explore the methods to check if command fails or succeeds and learn how to efficiently handle command failures in Bash scripting.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/nadiba.rahman?mibextid=ZbWKwL","article_published_time":"2024-02-08T10:31:32+00:00","article_modified_time":"2024-05-09T11:54:05+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Feature-image-Bash-check-if-command-fails-or-succeeds.png","type":"image\/png"}],"author":"Nadiba Rahman","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nadiba Rahman","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/"},"author":{"name":"Nadiba Rahman","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/69b717a03a5d9dc48e683aaffe22d33f"},"headline":"Check If Bash Command Fail or Succeed [Exit If Fail]","datePublished":"2024-02-08T10:31:32+00:00","dateModified":"2024-05-09T11:54:05+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/"},"wordCount":1660,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Feature-image-Bash-check-if-command-fails-or-succeeds.png","keywords":["if statement"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/","name":"Check If Bash Command Fail or Succeed [Exit If Fail] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Feature-image-Bash-check-if-command-fails-or-succeeds.png","datePublished":"2024-02-08T10:31:32+00:00","dateModified":"2024-05-09T11:54:05+00:00","description":"Explore the methods to check if command fails or succeeds and learn how to efficiently handle command failures in Bash scripting.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Feature-image-Bash-check-if-command-fails-or-succeeds.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Feature-image-Bash-check-if-command-fails-or-succeeds.png","width":400,"height":400,"caption":"Feature image-Bash check if command fails or succeeds"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-command-fails\/#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 Conditional Statements","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/"},{"@type":"ListItem","position":4,"name":"If Statement in Bash","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/"},{"@type":"ListItem","position":5,"name":"Check If Bash Command Fail or Succeed [Exit If Fail]"}]},{"@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\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/36406","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=36406"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/36406\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/36417"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=36406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=36406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=36406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}