{"id":37342,"date":"2024-02-20T07:43:55","date_gmt":"2024-02-20T07:43:55","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=37342"},"modified":"2024-03-17T06:11:17","modified_gmt":"2024-03-17T06:11:17","slug":"bash-exit-function","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/","title":{"rendered":"How to Exit From Function in Bash? [5 Ways]"},"content":{"rendered":"<p style=\"text-align: justify;\">While working with the bash function, you may encounter difficulties in exiting the function. However, there are some effective methods such as utilizing <strong>return, exit, break,<\/strong> etc., commands within scripts to resolve this issue. This article will demonstrate five ways to exit bash functions, along with addressing some common problems and solutions that may encountered during the process.<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Practice_Files_bash-exit-function.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 Exit From Bash Function<\/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\/functions\/return-values\/exit-function\/#5_Easy_Ways_to_Exit_From_Bash_Function\" >5 Easy Ways to Exit From Bash Function<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#1_Using_%E2%80%9Creturn%E2%80%9D_Statement\" >1. Using \u201creturn\u201d Statement<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#2_Using_%E2%80%9Cexit%E2%80%9D_Command\" >2. 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-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#3_Exit_Function_Based_on_User_Input\" >3. Exit Function Based on User Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#4_Using_%E2%80%9Cbreak%E2%80%9D_Command\" >4. Using \u201cbreak\u201d Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#5_Using_%E2%80%9Ctrap%E2%80%9D_Command\" >5. Using \u201ctrap\u201d Command<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#Differentiating_%E2%80%9Cexit%E2%80%9D_and_%E2%80%9Creturn%E2%80%9D_in_Bash_Function_Exit\" >Differentiating \u201cexit\u201d and \u201creturn\u201d in Bash Function Exit<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#Common_Issues_While_Exiting_from_Bash_Function\" >Common Issues While Exiting from Bash Function<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#A_Using_%E2%80%9Cexit%E2%80%9D_Instead_of_%E2%80%9Creturn%E2%80%9D\" >A. Using \u201cexit\u201d Instead of \u201creturn\u201d<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#B_Unexpected_Script_Termination\" >B. Unexpected Script Termination<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#C_Writing_%E2%80%9Creturn%E2%80%9D_Command_Outside_Function\" >C. Writing \u201creturn\u201d Command Outside Function<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#Practice_Tasks_on_How_to_Exit_from_Bash_Function\" >Practice Tasks on How to Exit from Bash Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#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-15\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#What_is_exit_command_in_Bash\" >What is exit command in Bash?<\/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\/functions\/return-values\/exit-function\/#What_is_return_statement_in_Bash\" >What is return statement 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\/functions\/return-values\/exit-function\/#Bash_exit_vs_return\" >Bash exit vs return?<\/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\/functions\/return-values\/exit-function\/#How_to_exit_bash_function_if_a_certain_condition_occurs\" >How to exit bash function if a certain condition occurs?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"5_Easy_Ways_to_Exit_From_Bash_Function\"><\/span>5 Easy Ways to Exit From Bash Function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In bash scripting, exiting a function is one of the most common tasks that everyone needs to know. In this section, I will go through 5 ways to exit the bash function in detail, so let\u2019s know them.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Using_%E2%80%9Creturn%E2%80%9D_Statement\"><\/span>1. Using \u201creturn\u201d Statement<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To exit from a bash function, use the <code class=\"\" data-line=\"\">return<\/code> statement. Once the function encounters the <strong>return<\/strong> statement, it stops executing the function. Moreover, the &#8220;return&#8221; statement returns an integer value between <strong>0<\/strong> to<strong> 255<\/strong> from the bash function. Value <strong>0<\/strong> indicates <strong>success<\/strong> and others are used to indicate failures. Follow the script to see how it works to exit the function:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\ncalculate_sum() {\n\u00a0\u00a0\u00a0 local number1=$1\n\u00a0\u00a0\u00a0 local number2=$2\n\u00a0\u00a0\u00a0 # Check if both numbers are provided\n\u00a0\u00a0\u00a0 if [ -z &quot;$number1&quot; ] || [ -z &quot;$number2&quot; ]; then\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &quot;Error: Please provide two numbers.&quot;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return 1\n\u00a0\u00a0\u00a0 fi\n\u00a0\u00a0\u00a0 # Calculate the sum\n\u00a0\u00a0\u00a0 local sum=$((number1 + number2))\n\u00a0\u00a0\u00a0 return $sum\n}\n# Call the function with two numbers\ncalculate_sum 5 3\n# Check the return value of the function\nreturn_value=$?\necho &quot;Sum of the two numbers: $return_value&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;\">This function <code class=\"\" data-line=\"\">calculate_sum<\/code> takes two parameters, <strong>number1<\/strong> and <strong>number2<\/strong>. It checks if both numbers are provided using the <strong><u><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/if-options\/#7_Bash_If_-z\" target=\"_blank\" rel=\"noopener\">-z operator<\/a><\/u><\/strong> in the <strong><u><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if\/\" target=\"_blank\" rel=\"noopener\">if statement<\/a><\/u><\/strong>. If either of the numbers is not provided, it prints an error message, &#8220;Error: Please provide two numbers.&#8221;, returns a non-zero value (return <strong>1<\/strong>), and ends the function.<\/p>\n<p style=\"text-align: justify;\">When both numbers are provided, it calculates the sum and stores it in the <strong>sum<\/strong> variable. The function then returns the sum using the return $sum. <code class=\"\" data-line=\"\">calculate_sum 5 3<\/code> calls the function with the arguments <strong>5<\/strong> and <strong>3<\/strong>. The return value is captured in the variable return_value using <strong><u><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/dollar-sign\/\" target=\"_blank\" rel=\"noopener\">$?<\/a><\/u><\/strong>.<\/div><\/div>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-37345\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.exit-bash-function-using-return-command.png\" alt=\"exit bash function using return command\" width=\"614\" height=\"97\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.exit-bash-function-using-return-command.png 614w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.exit-bash-function-using-return-command-300x47.png 300w\" sizes=\"(max-width: 614px) 100vw, 614px\" \/><\/p>\n<p style=\"text-align: justify;\">As you can see, the bash function returns<strong> 8<\/strong> by adding the numbers <strong>5<\/strong> and <strong>3<\/strong>.<\/p>\n<p style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">return<\/code> statement can also be used without a return value. Here\u2019s an example bash script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nmy_function() {\n\u00a0 echo &quot;Welcome to Linuxsimply&quot;\n\u00a0 return\n\u00a0 echo &quot;Hello, world!&quot;\n}\nmy_function<\/code><\/pre>\n<p style=\"text-align: justify;\">After running the script, it prints &#8220;Welcome to Linuxsimply&#8221; and then ends the script when the <code class=\"\" data-line=\"\">return<\/code> command inside the function is encountered:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-37346\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.exit-bash-function-using-return-command-with-no-argument.png\" alt=\"exit bash function using return command with no argument\" width=\"631\" height=\"94\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.exit-bash-function-using-return-command-with-no-argument.png 631w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.exit-bash-function-using-return-command-with-no-argument-300x45.png 300w\" sizes=\"(max-width: 631px) 100vw, 631px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Using_%E2%80%9Cexit%E2%80%9D_Command\"><\/span>2. Using \u201cexit\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <strong><u><a href=\"https:\/\/linuxsimply.com\/exit-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">exit command<\/a><\/u><\/strong> is used to exit the script or shell session. However, users need extra caution while using this command as it not only terminates the function but also the entire shell script. Additionally, it has an exit status from 0 to 255 like the <code class=\"\" data-line=\"\">return<\/code> statement. Now, see an example to learn how to exit from the bash function using the <code class=\"\" data-line=\"\">exit<\/code> command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nfunction file_existence() {\n\u00a0 if [[ -f &quot;$1&quot; ]]; then\n\u00a0\u00a0\u00a0 # File exists\n\u00a0\u00a0\u00a0 echo &quot;File &#039;$1&#039; found.&quot;\n\u00a0 else\n\u00a0\u00a0\u00a0 # File not found\n\u00a0\u00a0\u00a0 echo &quot;Error: File &#039;$1&#039; not found.&quot;\n\u00a0\u00a0\u00a0 exit 1\u00a0 # This exits the entire script\n\u00a0 fi\n}\nif file_existence &quot;hello.txt&quot;; then\n\u00a0 echo &quot;File exists&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;\">The <code class=\"\" data-line=\"\">file_existence<\/code> function takes a filename as an argument and checks whether it exists using the <code class=\"\" data-line=\"\">-f<\/code> test. If the file exists, it prints a message; otherwise, it prints an error message and exits the script with an exit status of <strong>1<\/strong>. The script then calls the <code class=\"\" data-line=\"\">file_existence<\/code> function with the argument &#8220;hello.txt&#8221;. If the defined file exists, it prints &#8220;File exists&#8221;. <\/div><\/div>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-37347\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.exit-bash-function-using-exit-command.png\" alt=\"exit bash function using exit command\" width=\"699\" height=\"130\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.exit-bash-function-using-exit-command.png 699w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.exit-bash-function-using-exit-command-300x56.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/p>\n<p style=\"text-align: justify;\">Since the \u201chello.txt\u201d is absent in the system, it shows an error and exits the entire shell script.<\/p>\n<p style=\"text-align: justify;\"><div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#e8f9fc;border-color:#ffffff;color:#333333;\">\n<p style=\"text-align: justify;\"><strong>Note: <\/strong>To exit the function as well as the whole script, the <code class=\"\" data-line=\"\">exit<\/code> command can be used without an argument (<strong>0-255<\/strong>) like the <strong>return<\/strong> command.<\/div><\/div>\n<h3><span class=\"ez-toc-section\" id=\"3_Exit_Function_Based_on_User_Input\"><\/span>3. Exit Function Based on User Input<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Based on user input, any function can be ended. In this example, the script uses a conditional <code class=\"\" data-line=\"\">if<\/code> statement to decide when to exit the function. The function will end as soon as a user writes \u201cexit\u201d to the console. Here\u2019s how:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\ncheck_user_input() {\n\u00a0\u00a0\u00a0 echo &quot;Enter &#039;exit&#039; to terminate the function:&quot;\n\u00a0\u00a0\u00a0 read user_input\n\u00a0\u00a0\u00a0 if [[ &quot;$user_input&quot; == &quot;exit&quot; ]]; then\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &quot;Exit the function.&quot;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return\n\u00a0\u00a0\u00a0 else\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &quot;Continue the function.&quot;\n\u00a0\u00a0\u00a0 fi\n}\n# Call the function\ncheck_user_input<\/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 Bash function named \u201ccheck_user_input\u201d is created. Inside the function, it prompts the user to enter an input. Then the <code class=\"\" data-line=\"\">read<\/code> command reads the user input. <code class=\"\" data-line=\"\">&quot;$user_input&quot; == &quot;exit&quot;<\/code> checks if the user input is \u201cexit\u201d,\u00a0 if it is, it prints the &#8220;Exit the function.&#8221; using the <strong><u><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/echo-command\/\" target=\"_blank\" rel=\"noopener\">echo command<\/a><\/u><\/strong> and exits the function due to the return command. If the user writes other than \u201cexit\u201d, it continues the function and echoes &#8220;Continue the function.&#8221;. <\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-37348\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.exit-bash-function-based-on-user-input.png\" alt=\"exit bash function based on user input\" width=\"700\" height=\"267\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.exit-bash-function-based-on-user-input.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.exit-bash-function-based-on-user-input-300x114.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p style=\"text-align: justify;\">In the first execution, I entered \u201cexit\u201d so the function ended. But when I entered \u201chello\u201d in the 2nd execution of the script, the function continued.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Using_%E2%80%9Cbreak%E2%80%9D_Command\"><\/span>4. Using \u201cbreak\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In bash, the <code class=\"\" data-line=\"\">break<\/code> statement is used to break loops. Here, a <code class=\"\" data-line=\"\">for<\/code> loop is created inside the function where the <strong>beak<\/strong> command exits both from the loop and the function. Here\u2019s how it works:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nfunction break_function() {\n\u00a0for i in {1..6}; do\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo $i\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if [ $i -eq 4 ]; then\n\u00a0\u00a0\u00a0\u00a0\u00a0   break # Exit the loop and function\n\u00a0\u00a0\u00a0    fi\n\u00a0done\n}\nbreak_function<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">The script defines a function called <code class=\"\" data-line=\"\">break_function<\/code> that contains a <code class=\"\" data-line=\"\">for<\/code> loop. Inside the loop, it prints the value of <strong>i<\/strong>, and if <strong>i<\/strong> is equal to 4 <code class=\"\" data-line=\"\">($i -eq 4)<\/code>, the <code class=\"\" data-line=\"\">break<\/code> statement is executed, causing the loop and the function to terminate.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-37350\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/6.exit-bash-function-using-break-command.png\" alt=\"exit bash function using break command\" width=\"582\" height=\"191\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/6.exit-bash-function-using-break-command.png 582w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/6.exit-bash-function-using-break-command-300x98.png 300w\" sizes=\"(max-width: 582px) 100vw, 582px\" \/><\/p>\n<p style=\"text-align: justify;\">The picture illustrates the termination of both the loop and function when the value of <strong>i<\/strong> becomes <strong>4<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"5_Using_%E2%80%9Ctrap%E2%80%9D_Command\"><\/span>5. Using \u201ctrap\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Exiting from the bash function can be achieved using the <strong><u><a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/error-handling-and-debugging\/error-handling\/trap-err\/#What_is_trap_Command_in_Bash\" target=\"_blank\" rel=\"noopener\">trap command<\/a><\/u><\/strong>. In this example, the <code class=\"\" data-line=\"\">trap<\/code> command catches the <code class=\"\" data-line=\"\">SIGINT<\/code> signal which is usually generated by pressing <strong>CTRL+C<\/strong>, and exits the function. Here\u2019s the bash script to accomplish this task:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nmy_function() {\n\u00a0 trap &quot;cleanup_and_exit&quot; SIGINT # Call cleanup_and_exit function on Ctrl+C\n\u00a0 echo &quot;Function started. Press Ctrl+C to exit gracefully.&quot;\n\u00a0 sleep 10\n\u00a0 # This line will not be reached if Ctrl+C is pressed during sleep\n\u00a0 echo &quot;Function completed.&quot;\n}\ncleanup_and_exit() {\n\u00a0 echo &quot;Ctrl+C detected. Cleaning up and exiting.&quot;\n\u00a0\u00a0exit 1\n}\n\n# Call the function\nmy_function\n\n# This line will not be reached if Ctrl+C is pressed during my_function\necho &quot;Script continues after function call.&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;\">The <code class=\"\" data-line=\"\">my_function<\/code> function sets up a <code class=\"\" data-line=\"\">trap<\/code> using <code class=\"\" data-line=\"\">trap &quot;cleanup_and_exit&quot; SIGINT<\/code>. It indicates that when the <strong>SIGINT<\/strong> signal <strong>(CTRL+C)<\/strong> is received, the <code class=\"\" data-line=\"\">cleanup_and_exit<\/code> function should be called.<\/p>\n<p style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">cleanup_and_exit<\/code> function is responsible for cleaning up resources or performing any necessary actions before exiting the script with a status of 1.<\/p>\n<p style=\"text-align: justify;\">Then the function simulates some work with <code class=\"\" data-line=\"\">sleep 10<\/code>. If <strong>Ctrl+C<\/strong> is pressed during this sleep, the <code class=\"\" data-line=\"\">trap<\/code> will be triggered, and the <code class=\"\" data-line=\"\">cleanup_and_exit<\/code> function will be executed. The subsequent line &#8220;Script continues after function call.&#8221; will not be reached if <strong>CTRL+C<\/strong> is pressed during the execution of <code class=\"\" data-line=\"\">my_function<\/code>.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-37349\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.exit-bash-function-using-trap-command.png\" alt=\"exit bash function using trap command\" width=\"825\" height=\"151\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.exit-bash-function-using-trap-command.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.exit-bash-function-using-trap-command-300x55.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.exit-bash-function-using-trap-command-768x141.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p style=\"text-align: justify;\">You can see that after starting the function as soon as I entered <strong>CTRL+C<\/strong>, the function terminated.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Differentiating_%E2%80%9Cexit%E2%80%9D_and_%E2%80%9Creturn%E2%80%9D_in_Bash_Function_Exit\"><\/span>Differentiating \u201cexit\u201d and \u201creturn\u201d in Bash Function Exit<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Though both <code class=\"\" data-line=\"\">exit<\/code> and <code class=\"\" data-line=\"\">return<\/code> commands have exit codes between 0 and 255, they have a couple of differences:<\/p>\n<div class=\"su-table su-table-responsive su-table-alternate su-table-fixed\">\n<table style=\"height: 188px;width: 100%\" width=\"100%\">\n<tbody>\n<tr style=\"height: 25px\">\n<th style=\"height: 25px\" width=\"312\"><strong>\u201cexit\u201d Command<\/strong><\/th>\n<th style=\"height: 25px\" width=\"312\"><strong>\u201creturn\u201d Command<\/strong><\/th>\n<\/tr>\n<tr style=\"height: 102px\">\n<td style=\"text-align: center;height: 102px\" width=\"312\">The exit command is used to terminate the entire shell script.<\/td>\n<td style=\"text-align: center;height: 102px\" width=\"312\">The return command does not end the entire shell session, it terminates the function and returns control to the calling code.<\/td>\n<\/tr>\n<tr style=\"height: 10px\">\n<td style=\"text-align: center;height: 10px\" width=\"312\">It can be called inside and outside of a function.<\/td>\n<td style=\"text-align: center;height: 10px\" width=\"312\">It is used only within functions.<\/td>\n<\/tr>\n<tr style=\"height: 51px\">\n<td style=\"text-align: center;height: 51px\" width=\"312\">The exit can be used interactively.<\/td>\n<td style=\"text-align: center;height: 51px\" width=\"312\">The return statement can not be used interactively.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#e8f9fc;border-color:#ffffff;color:#333333;\">\n<p style=\"text-align: justify;\"><strong>Note:<\/strong> However, the <code class=\"\" data-line=\"\">exit<\/code> command is not recommended for use inside a function, as it can lead to unexpected behavior if the function is called from within another function.<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Common_Issues_While_Exiting_from_Bash_Function\"><\/span>Common Issues While Exiting from Bash Function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">You may encounter some problems while exiting from the bash function. Let&#8217;s take a look at these problems and how to solve them:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"A_Using_%E2%80%9Cexit%E2%80%9D_Instead_of_%E2%80%9Creturn%E2%80%9D\"><\/span>A. Using \u201cexit\u201d Instead of \u201creturn\u201d<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">It is not a good practice to use the <code class=\"\" data-line=\"\">exit<\/code> command instead of the <code class=\"\" data-line=\"\">return<\/code> command to exit out of a bash function. Because it will terminate the whole shell session, not just the function preventing any subsequent code from being executed. So if you want to only exit the function and continue with the rest of the script, use the <code class=\"\" data-line=\"\">return<\/code> statement instead of the <code class=\"\" data-line=\"\">exit<\/code> command.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"B_Unexpected_Script_Termination\"><\/span>B. Unexpected Script Termination<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Unexpected script termination can occur if you misplace the <code class=\"\" data-line=\"\">exit<\/code> command inside the function in bash like this:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nfunction example_function() {\n   if [ &quot;$some_condition&quot; = &quot;true&quot; ]; then\n      exit 0\u00a0 # Incorrect: Exits the entire script, not just the function\n   fi\n}\n\n# Call the function\nexample_function\n\n# The script continues here after the function call\necho &quot;Script continues.&quot;<\/code><\/pre>\n<p style=\"text-align: justify;\">In this script, if <code class=\"\" data-line=\"\">some_condition<\/code> is equal to &#8220;true&#8221;, no output will be generated after the function call because the script exits within the function. Therefore, be mindful of using the <code class=\"\" data-line=\"\">exit<\/code> command.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"C_Writing_%E2%80%9Creturn%E2%80%9D_Command_Outside_Function\"><\/span>C. Writing \u201creturn\u201d Command Outside Function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">If you write a <code class=\"\" data-line=\"\">return<\/code> command outside the function, it may not produce the results as expected. So to avoid this issue, always write this command inside the bash function.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Practice_Tasks_on_How_to_Exit_from_Bash_Function\"><\/span>Practice Tasks on How to Exit from Bash Function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To enhance your Bash scripting abilities and learn how to exit a Bash function, try the following:<\/p>\n<ol>\n<li style=\"text-align: justify;\">Define a Bash function that checks if the number is odd, if so, exit the function.<\/li>\n<li style=\"text-align: justify;\">Write a function that simulates a simple calculator. It should take two numbers and an operator as input, perform the operation (addition, subtraction, multiplication, or division), and then exit with 0 on success or a non-zero code for errors (division by zero, invalid operator).<\/li>\n<li style=\"text-align: justify;\">Create a function that reads lines from a file until it encounters a specific keyword. Each line should be printed, and the function should exit with 0 when the keyword is found or 1 when the end of the file is reached without finding the keyword.<\/li>\n<li style=\"text-align: justify;\">Generate a function that acts like a timer. It should take a duration in seconds as input, wait for that amount of time, and then exit with 0. However, if the user presses CTRL+C during the wait, the function should exit immediately with a specific non-zero code.<\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To wrap up, I have listed 5 ways to exit from function in Bash. In addition, I have also discussed some common problems encountered while trying to exit from the bash function. Read this article carefully to improve your bash scripting skills. Good luck!<\/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=\"What_is_exit_command_in_Bash\"><\/span>What is exit command in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">exit<\/code> command in bash is used to end a script or a shell session. It assigns an exit status, ranging from <strong>0<\/strong> to <strong>255<\/strong>, where <strong>0<\/strong> signifies success and values from<strong> 1<\/strong> to <strong>255<\/strong> denote various error types. This is the syntax of the <code class=\"\" data-line=\"\">exit<\/code> command:<\/p>\n<p><code class=\"\" data-line=\"\">exit n<\/code>, where <strong>n<\/strong> represents the numeric value from 0 to 255.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_return_statement_in_Bash\"><\/span>What is return statement in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">return<\/code> statement is used within functions to end a function and returns values to the caller script. When a function meets the <strong>return<\/strong> statement, it immediately exits the function. This is the syntax of the <code class=\"\" data-line=\"\">return<\/code> statement:<\/p>\n<p style=\"text-align: justify;\"><code class=\"\" data-line=\"\">return n<\/code>, where <strong>n<\/strong> represents the numeric value from <strong>0 to 255<\/strong>. A value of <strong>0<\/strong> is considered a successful operation, while values ranging from <strong>1 to 255<\/strong> indicate failures.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Bash_exit_vs_return\"><\/span>Bash exit vs return?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The main difference between an <code class=\"\" data-line=\"\">exit<\/code> and a <code class=\"\" data-line=\"\">return<\/code> command is that an <strong>exit<\/strong> command terminates the execution of a bash script while a <strong>return<\/strong> command terminates the execution of a bash function. An &#8216;exit&#8217; command can be executed inside or outside of a bash function, whereas a &#8216;return&#8217; command should be executed inside a bash function.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_exit_bash_function_if_a_certain_condition_occurs\"><\/span>How to exit bash function if a certain condition occurs?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To exit the bash function based on a certain condition, use the <code class=\"\" data-line=\"\">if<\/code> statement inside the function to check the condition. If the condition is true, use the <code class=\"\" data-line=\"\">exit<\/code> command with an appropriate exit code (<strong>0-255<\/strong>) to signal the reason for early termination. Here\u2019s an example bash script for this:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nfunction check_file_size() {\n local file_name=&quot;$1&quot;\n local max_size=1024 # In kilobytes\n if [[ ! -f &quot;$file_name&quot; ]]; then\n   echo &quot;Error: File &#039;$file_name&#039; does not exist.&quot;\n   exit 1\n fi\n local file_size=$(stat -c%s &quot;$file_name&quot;)\n if [[ $file_size -gt $(($max_size * 1024)) ]]; then\n   echo &quot;Error: File &#039;$file_name&#039; is too large (exceeds $max_size KB).&quot;\n   exit 2\n fi\n# Rest of the function logic...\n}<\/code><\/pre>\n<p style=\"text-align: justify;\">This script checks if the file exists and is within the size limit. If either condition fails, it exits with an informative message and a specific exit code.<\/p>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": {\n    \"@type\": \"Question\",\n    \"name\": \"Bash exit vs return?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"The main difference between an exit and a return command is that an exit command terminates the execution of a bash script while a return command terminates the execution of a bash function. An 'exit' command can be executed inside or outside of a bash function, whereas a 'return' command should be executed inside a bash function.\"\n    }\n  }\n}\n<\/script><\/p>\n<p><span style=\"font-size: 18pt; color: #003366;\"><strong>Related Articles<\/strong><\/span><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/return-0\/\" target=\"_blank\" rel=\"noopener\">How to Return Exit status \u201c0\u201d in Bash [6 Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/return-string-function\/\" target=\"_blank\" rel=\"noopener\">How to Return String From Bash Function [4 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/return-boolean-function\/\" target=\"_blank\" rel=\"noopener\">How to Return Boolean From Bash Function [6 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/return-function-array\/\" target=\"_blank\" rel=\"noopener\">How to Return Array From Bash Function? [7 Methods]<\/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;Return Values From Bash Function&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\/functions\/return-values\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/\" target=\"_blank\" rel=\"noopener\">Return Values From Bash Function<\/a><\/span> | <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Functions&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\/functions\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/\" target=\"_blank\" rel=\"noopener\">Bash Functions<\/a><\/span>\u00a0| <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;37342&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;5&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&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;5\\\/5 - (5 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;How to Exit From Function in Bash? [5 Ways]&quot;,&quot;width&quot;:&quot;142.5&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: 142.5px;\">\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            5\/5 - (5 votes)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>While working with the bash function, you may encounter difficulties in exiting the function. However, there are some effective methods &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Exit From Function in Bash? [5 Ways]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#more-37342\" aria-label=\"Read more about How to Exit From Function in Bash? [5 Ways]\">Read more<\/a><\/p>\n","protected":false},"author":314908,"featured_media":37351,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[201],"class_list":["post-37342","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-return-values","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Exit From Function in Bash? [5 Ways] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"This article contains 5 ways to exit from Bash function. Also, some common issues and their solutions while exiting functions are addressed.\" \/>\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\/functions\/return-values\/exit-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Exit From Function in Bash? [5 Ways] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"This article contains 5 ways to exit from Bash function. Also, some common issues and their solutions while exiting functions are addressed.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/mitalimostakim.mou\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-20T07:43:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-17T06:11:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-exit-function.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=\"Mitu Akter Mou\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mitu Akter Mou\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 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\\\/functions\\\/return-values\\\/exit-function\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/\"},\"author\":{\"name\":\"Mitu Akter Mou\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/54b35370776bb6a79376ea0135412689\"},\"headline\":\"How to Exit From Function in Bash? [5 Ways]\",\"datePublished\":\"2024-02-20T07:43:55+00:00\",\"dateModified\":\"2024-03-17T06:11:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/\"},\"wordCount\":1856,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/bash-exit-function.png\",\"keywords\":[\"return values\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/\",\"name\":\"How to Exit From Function in Bash? [5 Ways] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/bash-exit-function.png\",\"datePublished\":\"2024-02-20T07:43:55+00:00\",\"dateModified\":\"2024-03-17T06:11:17+00:00\",\"description\":\"This article contains 5 ways to exit from Bash function. Also, some common issues and their solutions while exiting functions are addressed.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/bash-exit-function.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/bash-exit-function.png\",\"width\":400,\"height\":400,\"caption\":\"Bash exit function\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/exit-function\\\/#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 Functions\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Return Values From Bash Function\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/return-values\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to Exit From Function in Bash? [5 Ways]\"}]},{\"@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\\\/54b35370776bb6a79376ea0135412689\",\"name\":\"Mitu Akter Mou\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mitu-Akter-Mou-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mitu-Akter-Mou-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mitu-Akter-Mou-II-96x96.png\",\"caption\":\"Mitu Akter Mou\"},\"description\":\"Hello, This is Mitu Akter Mou, currently working as a Linux Content Developer Executive at SOFTEKO for the Linuxsimply project. I hold a bachelor's degree in Biomedical Engineering from Khulna University of Engineering &amp; Technology (KUET). Experiencing new stuff and gathering insights from them seems very happening to me. My goal here is to simplify the life of Linux users by making creative articles, blogs, and video content for all of them. Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/mitalimostakim.mou\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/mitu-akter-mou-915537198\\\/\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/mou\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Exit From Function in Bash? [5 Ways] - LinuxSimply","description":"This article contains 5 ways to exit from Bash function. Also, some common issues and their solutions while exiting functions are addressed.","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\/functions\/return-values\/exit-function\/","og_locale":"en_US","og_type":"article","og_title":"How to Exit From Function in Bash? [5 Ways] - LinuxSimply","og_description":"This article contains 5 ways to exit from Bash function. Also, some common issues and their solutions while exiting functions are addressed.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/mitalimostakim.mou\/","article_published_time":"2024-02-20T07:43:55+00:00","article_modified_time":"2024-03-17T06:11:17+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-exit-function.png","type":"image\/png"}],"author":"Mitu Akter Mou","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mitu Akter Mou","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/"},"author":{"name":"Mitu Akter Mou","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/54b35370776bb6a79376ea0135412689"},"headline":"How to Exit From Function in Bash? [5 Ways]","datePublished":"2024-02-20T07:43:55+00:00","dateModified":"2024-03-17T06:11:17+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/"},"wordCount":1856,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-exit-function.png","keywords":["return values"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/","name":"How to Exit From Function in Bash? [5 Ways] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-exit-function.png","datePublished":"2024-02-20T07:43:55+00:00","dateModified":"2024-03-17T06:11:17+00:00","description":"This article contains 5 ways to exit from Bash function. Also, some common issues and their solutions while exiting functions are addressed.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-exit-function.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/bash-exit-function.png","width":400,"height":400,"caption":"Bash exit function"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/exit-function\/#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 Functions","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/"},{"@type":"ListItem","position":4,"name":"Return Values From Bash Function","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/return-values\/"},{"@type":"ListItem","position":5,"name":"How to Exit From Function in Bash? [5 Ways]"}]},{"@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\/54b35370776bb6a79376ea0135412689","name":"Mitu Akter Mou","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mitu-Akter-Mou-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mitu-Akter-Mou-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mitu-Akter-Mou-II-96x96.png","caption":"Mitu Akter Mou"},"description":"Hello, This is Mitu Akter Mou, currently working as a Linux Content Developer Executive at SOFTEKO for the Linuxsimply project. I hold a bachelor's degree in Biomedical Engineering from Khulna University of Engineering &amp; Technology (KUET). Experiencing new stuff and gathering insights from them seems very happening to me. My goal here is to simplify the life of Linux users by making creative articles, blogs, and video content for all of them. Read Full Bio","sameAs":["https:\/\/www.facebook.com\/mitalimostakim.mou\/","https:\/\/www.linkedin.com\/in\/mitu-akter-mou-915537198\/"],"url":"https:\/\/linuxsimply.com\/author\/mou\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/37342","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\/314908"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=37342"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/37342\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/37351"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=37342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=37342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=37342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}