{"id":35950,"date":"2024-02-04T10:28:33","date_gmt":"2024-02-04T10:28:33","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=35950"},"modified":"2024-04-03T05:45:12","modified_gmt":"2024-04-03T05:45:12","slug":"call-bash-function","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/","title":{"rendered":"How to Call a Function in Bash [7 Cases]"},"content":{"rendered":"<p style=\"text-align: justify;\">Calling Bash functions is as simple as invoking a Bash command. To call an already-declared Bash function, use the function name as if it were a Bash command. For instance, to invoke a function declared as <strong>fname() { command; }<\/strong>, type <strong>fname<\/strong> in the terminal or within the script where the function is defined. This article talks about 7 different cases of calling functions in the Bash shell.<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Practice-Files_call-bash-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 of Calling 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\/call-function\/#1_Calling_a_Function_Defined_in_the_Terminal\" >1. Calling a Function Defined in the Terminal<\/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\/functions\/call-function\/#2_%E2%80%9Csource%E2%80%9D_Command_to_Call_Function_Written_in_a_Script\" >2. \u201csource\u201d Command to Call Function Written in a Script<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#3_Calling_Functions_Inside_Bash_Script_File\" >3. Calling Functions Inside Bash Script File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#4_Function_Calling_As_an_Argument_of_a_Bash_Script\" >4. Function Calling As an Argument of a Bash Script<\/a><\/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\/functions\/call-function\/#5_Calling_a_Function_in_a_Script_from_a_Separate_Script\" >5. Calling a Function in a Script from a Separate Script<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#6_Calling_a_Function_Inside_Another_Function\" >6. Calling a Function Inside Another Function<\/a><\/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\/call-function\/#7_Calling_Function_With_Arguments_in_Bash\" >7. Calling Function With Arguments in Bash<\/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\/call-function\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-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-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#How_to_store_function_output_to_a_variable\" >How to store function output to a variable?<\/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\/call-function\/#Can_I_call_a_function_from_a_script_rather_than_executing_the_whole_script\" >Can I call a function from a script rather than executing the whole script?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#How_do_you_call_a_function_within_an_if_statement_in_Bash\" >How do you call a function within an if statement 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\/functions\/call-function\/#Why_does_invoking_a_function_show_that_the_function_doesnt_exist\" >Why does invoking a function show that the function doesn\u2019t exist?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"1_Calling_a_Function_Defined_in_the_Terminal\"><\/span>1. Calling a Function Defined in the Terminal<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Think about a function defined in the terminal as follows:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">func1 () {\necho &quot;Hello from a Bash function&quot;\n}<\/code><\/pre>\n<p style=\"text-align: justify;\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-35951\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.-Defining-a-function-in-the-terminal.png\" alt=\"Defining a function in the terminal\" width=\"551\" height=\"104\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.-Defining-a-function-in-the-terminal.png 551w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.-Defining-a-function-in-the-terminal-300x57.png 300w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/>To call the function write the function name like a Bash command. For instance, just writing the function name <code class=\"\" data-line=\"\">func1<\/code> executes the \u201dfunc1\u201d function defined in the terminal.<img decoding=\"async\" class=\"aligncenter size-full wp-image-35952\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.-Calling-a-function-defined-in-the-terminal.png\" alt=\"Calling a function defined in the terminal\" width=\"611\" height=\"207\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.-Calling-a-function-defined-in-the-terminal.png 611w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.-Calling-a-function-defined-in-the-terminal-300x102.png 300w\" sizes=\"(max-width: 611px) 100vw, 611px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"2_%E2%80%9Csource%E2%80%9D_Command_to_Call_Function_Written_in_a_Script\"><\/span>2. \u201csource\u201d Command to Call Function Written in a Script<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">A function written in a Bash script can be called using the <strong>source<\/strong> command. Say you have a script that contains a function. To call the function first source the script by the source command. Then write the function name like a Bash command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nfunction greet()\n{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &quot;Welcome to LinuxSimply&quot;\n}<\/code><\/pre>\n<pre><code class=\"language-bash\" data-line=\"\">source welcome.sh<\/code><\/pre>\n<p style=\"text-align: justify;\">After sourcing the <strong>welcome.sh<\/strong> file, writing \u201cgreet\u201d calls the <code class=\"\" data-line=\"\">greet<\/code> function defined in the <strong>welcome.sh<\/strong> file.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">greet<\/code><\/pre>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-35953\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.-Calling-a-function-using-the-source-command.png\" alt=\"Calling a function using the source command\" width=\"590\" height=\"183\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.-Calling-a-function-using-the-source-command.png 590w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.-Calling-a-function-using-the-source-command-300x93.png 300w\" sizes=\"(max-width: 590px) 100vw, 590px\" \/>The output shows the message \u201cWelcome to LinuxSimply\u201d which is written inside the function.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"3_Calling_Functions_Inside_Bash_Script_File\"><\/span>3. Calling Functions Inside Bash Script File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">One can invoke a function like a bash command inside the bash script that contains the function. After that follow the usual steps to execute the script. But make sure the function definition precedes the function call.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nfunction greet()\n{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 echo &quot;Welcome to LinuxSimply&quot;\n}\n# function call\ngreet<\/code><\/pre>\n<p style=\"text-align: justify;\">In the last line of the script, <code class=\"\" data-line=\"\">greet<\/code> invokes the function \u201cgreet\u201c defined in the script.<\/p>\n<p style=\"text-align: justify;\">To make the bash script executable, use the below code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">chmod u+x welcome.sh<\/code><\/pre>\n<p style=\"text-align: justify;\">Replace the filename with your filename. Finally, execute the file to see the output of the function:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/welcome.sh<\/code><\/pre>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-35954\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.-Calling-a-function-in-Bash-script.png\" alt=\"Calling a function in Bash script\" width=\"589\" height=\"140\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.-Calling-a-function-in-Bash-script.png 589w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.-Calling-a-function-in-Bash-script-300x71.png 300w\" sizes=\"(max-width: 589px) 100vw, 589px\" \/>Upon execution, the script shows the output of the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/echo-command\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a> written inside the function.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"4_Function_Calling_As_an_Argument_of_a_Bash_Script\"><\/span>4. Function Calling As an Argument of a Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Calling functions as an argument of a script is an elegant technique. This is super useful when users have multiple functions in a script. To call a function supply the function name as an argument while executing the script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nfunction f1()\n{\n\u00a0\u00a0\u00a0echo &quot;Hello Linux Users&quot;\n}\nfunction f2()\n{\n\u00a0\u00a0\u00a0echo &quot;This is a Bash function.&quot;\n}\nfunction f3()\n{\n\u00a0\u00a0\u00a0echo &quot;This is another Bash function.&quot;\n}\nf_call=$1; shift; $f_call &quot;$@&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>The script contains <strong>f1<\/strong>, <strong>f2<\/strong> and <strong>f3<\/strong> functions. The variable <code class=\"\" data-line=\"\">f_call<\/code> is assigned the value of the first command-line argument ($1), which should be the name of the function to be called.<\/p>\n<p>The <strong>shift<\/strong> command is used to shift the command-line arguments to the left, effectively discarding the first argument (the function name). Finally, the specified function ($f_call) is called with any remaining command-line arguments (&#8220;$@&#8221;). This allows users to pass additional arguments to the chosen function.<\/p>\n<p style=\"text-align: justify;\"><\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-35955\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.-Calling-function-as-argument-of-an-script.png\" alt=\"Calling function as argument of an script\" width=\"524\" height=\"226\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.-Calling-function-as-argument-of-an-script.png 524w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.-Calling-function-as-argument-of-an-script-300x129.png 300w\" sizes=\"(max-width: 524px) 100vw, 524px\" \/>In the first execution, the script is executed and calls the <strong>f1<\/strong> function cause f1 is provided as the first positional argument.<\/p>\n<p style=\"text-align: justify;\">In the second execution, nothing is provided as a positional argument. Hence no function is called.<\/p>\n<p style=\"text-align: justify;\">At last, the third execution calls the function <strong>f3<\/strong> and shows its output.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"5_Calling_a_Function_in_a_Script_from_a_Separate_Script\"><\/span>5. Calling a Function in a Script from a Separate Script<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Use the <strong>source<\/strong> command or the . (dot) operator to call a function defined in one script from another script in Bash. This allows you to include the content of one script into another, making the functions from the first script available in the second one:<\/p>\n<p><span style=\"color: #800080;\"><strong>Script 1 &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nfunction greet() {\n\u00a0\u00a0\u00a0 echo &quot;Hello from script1.sh&quot;\n}<\/code><\/pre>\n<p><span style=\"color: #800080;\"><strong>Script 2 &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n# Source the first script to make its functions available\nsource script1.sh\n\n# Call the function from the first script\ngreet<\/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, the <strong>script1.sh<\/strong> contains a function <code class=\"\" data-line=\"\">greet<\/code>. <strong>script2.sh<\/strong> sources the <strong>script1.sh<\/strong> by the source command. After sourcing the first script, the function \u201cgreet\u201c is called by its name.<\/p>\n<p style=\"text-align: justify;\"><\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-35956\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/6.-Calling-function-of-separate-script-in-a-script.png\" alt=\"Calling function of separate script in a script\" width=\"475\" height=\"112\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/6.-Calling-function-of-separate-script-in-a-script.png 475w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/6.-Calling-function-of-separate-script-in-a-script-300x71.png 300w\" sizes=\"(max-width: 475px) 100vw, 475px\" \/>Execution of <strong>script2.sh<\/strong> shows that the \u201cgreet\u201c function of <strong>script1.sh<\/strong> is available and properly called in the second script.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"6_Calling_a_Function_Inside_Another_Function\"><\/span>6. Calling a Function Inside Another Function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To call a function inside another function, simply write the function name within the body of the main function:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\nf1 ()\n{\necho &quot;This is the first function.&quot;\n# Calling f2 inside f1\nf2\n}\n\nf2 ()\n{\necho &quot;This is the second function.&quot;\n}\n\n# Calling f1\nf1<\/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>The bash script defines two functions <strong>f1<\/strong> and <strong>f2<\/strong>. The f2 function is called inside the f1 function.<\/p>\n<p style=\"text-align: justify;\"><\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-35957\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/7.-Calling-a-function-inside-another-function.png\" alt=\"Calling a function inside another function\" width=\"478\" height=\"141\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/7.-Calling-a-function-inside-another-function.png 478w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/7.-Calling-a-function-inside-another-function-300x88.png 300w\" sizes=\"(max-width: 478px) 100vw, 478px\" \/>Once f1 function is called it executes both f1 and f2 as you can see in the image above.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"7_Calling_Function_With_Arguments_in_Bash\"><\/span>7. Calling Function With Arguments in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Provide the argument after the function name when calling the function. The \u201cwelcome\u201c function of the following script requires an argument for proper execution:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nwelcome () {\n\u00a0 echo &quot;Hello $1. Welcome to LinuxSimply&quot;\n}\n\nwelcome &quot;Anita&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><code class=\"\" data-line=\"\">welcome &quot;Anita&quot;<\/code> calls the welcome function with the argument \u201cAnita\u201d. The function utilizes this argument when it uses the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/parameters\/positional-parameters\/\" target=\"_blank\" rel=\"noopener\"><strong>positional parameter<\/strong><\/a> <strong>$1<\/strong> to refer to the argument.<\/p>\n<p style=\"text-align: justify;\"><\/div><\/div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-35958\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/8.-Calling-function-with-arguments-in-Bash.png\" alt=\"Calling function with arguments in Bash\" width=\"604\" height=\"128\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/8.-Calling-function-with-arguments-in-Bash.png 604w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/8.-Calling-function-with-arguments-in-Bash-300x64.png 300w\" sizes=\"(max-width: 604px) 100vw, 604px\" \/>The program successfully prints a welcome message utilizing the argument \u201cAnita\u201d.<\/p>\n<p style=\"text-align: justify;\">To supply multiple arguments to a function place them one after one separated by a space.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In conclusion, calling a Bash function is straightforward yet important. While it is easy to invoke a function, the context in which a function is called may vary. Regardless of the scenario, users must verify that functions are defined before attempting to call them. This simple precaution ensures a smooth execution and helps prevent errors while calling a function.<\/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_store_function_output_to_a_variable\"><\/span>How to store function output to a variable?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To store function output to a variable, use <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/set-variable-to-output-of-command\/\" target=\"_blank\" rel=\"noopener\"><strong>command substitution<\/strong><\/a>. Enclose the function name with parenthesis and put a dollar sign before the starting parenthesis like- <strong>$(func_name)<\/strong>. Then assign it to a variable such as- <code class=\"\" data-line=\"\">result=$(func_name)<\/code>. The \u201cresult\u201c variable contains the output of the function.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_call_a_function_from_a_script_rather_than_executing_the_whole_script\"><\/span>Can I call a function from a script rather than executing the whole script?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\"><strong>Yes<\/strong>, you can call a specific function from a script without executing the entire script. You can adapt various techniques to achieve that. The common approach is passing the function name as an argument.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_you_call_a_function_within_an_if_statement_in_Bash\"><\/span>How do you call a function within an if statement in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To call a function within an if statement in Bash, you can use the following syntax:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">if function_name; then\n\u00a0\u00a0 # codes\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\">This ensures that your function returns an exit status (0) for the if condition to be true, indicating successful execution.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Why_does_invoking_a_function_show_that_the_function_doesnt_exist\"><\/span>Why does invoking a function show that the function doesn\u2019t exist?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">If invoking a function shows that the function doesn&#8217;t exist, there could be several reasons for this issue. Typically this issue is raised when a function is defined after attempting to invoke it.<\/p>\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 store function output to a variable?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To store function output to a variable, use command substitution. Enclose the function name with parenthesis and put a dollar sign before the starting parenthesis like- $(func_name). Then assign it to a variable such as- result=$(func_name). The \u201cresult\u201c variable contains the output of the function.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Can I call a function from a script rather than executing the whole script?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Yes, you can call a specific function from a script without executing the entire script. You can adapt various techniques to achieve that. The common approach is passing the function name as an argument.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"How do you call a function within an if statement in Bash?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To call a function within an if statement in Bash, you can use the following syntax:<\/p>\n<p>if function_name; then\n\u00a0\u00a0 # codes\nfi<\/p>\n<p>This ensures that your function returns an exit status (0) for the if condition to be true, indicating successful execution.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Why does invoking a function show that the function doesn\u2019t exist?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"If invoking a function shows that the function doesn't exist, there could be several reasons for this issue. Typically this issue is raised when a function is defined after attempting to invoke it.\"\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\/define-function\/\" target=\"_blank\" rel=\"noopener\">How to Define a Function in Bash [2 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/function-variables\/\" target=\"_blank\" rel=\"noopener\">Variables in Bash Function [Easy Reference]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/bash-script-options\/\" target=\"_blank\" rel=\"noopener\">How to Add Options in a Bash Script [2 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/alias\/\" target=\"_blank\" rel=\"noopener\">How to Use Alias And Functions in Bash [Reference Manual]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/script-argument\/\" target=\"_blank\" rel=\"noopener\">Argument in Bash Script<\/a><\/strong><\/li>\n<li><strong><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><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/overriding-commands\/\" target=\"_blank\" rel=\"noopener\">Overriding Commands in Bash<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/function-examples\/\" target=\"_blank\" rel=\"noopener\">Bash Function 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;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> | <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;35950&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;4&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;4\\\/5 - (5 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;How to Call a Function in Bash [7 Cases]&quot;,&quot;width&quot;:&quot;113.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: 113.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            4\/5 - (5 votes)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Calling Bash functions is as simple as invoking a Bash command. To call an already-declared Bash function, use the function &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Call a Function in Bash [7 Cases]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#more-35950\" aria-label=\"Read more about How to Call a Function in Bash [7 Cases]\">Read more<\/a><\/p>\n","protected":false},"author":314903,"featured_media":35959,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[195],"class_list":["post-35950","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-bash-functions","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 Call a Function in Bash [7 Cases] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"Bash users must know how to call bash function. This article discusses different cases of calling a Bash function.\" \/>\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\/call-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Call a Function in Bash [7 Cases] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"Bash users must know how to call bash function. This article discusses different cases of calling a Bash function.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/zahidlaku72\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-04T10:28:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-03T05:45:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/call-bash-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=\"Md Zahidul Islam Laku\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Md Zahidul Islam Laku\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 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\\\/call-function\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-function\\\/\"},\"author\":{\"name\":\"Md Zahidul Islam Laku\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/26b37b2c7517d2c8702472bc3986ef21\"},\"headline\":\"How to Call a Function in Bash [7 Cases]\",\"datePublished\":\"2024-02-04T10:28:33+00:00\",\"dateModified\":\"2024-04-03T05:45:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-function\\\/\"},\"wordCount\":1145,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-function\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/call-bash-function.png\",\"keywords\":[\"bash functions\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-function\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-function\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-function\\\/\",\"name\":\"How to Call a Function in Bash [7 Cases] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-function\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-function\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/call-bash-function.png\",\"datePublished\":\"2024-02-04T10:28:33+00:00\",\"dateModified\":\"2024-04-03T05:45:12+00:00\",\"description\":\"Bash users must know how to call bash function. This article discusses different cases of calling a Bash function.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-function\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-function\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-function\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/call-bash-function.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/call-bash-function.png\",\"width\":400,\"height\":400,\"caption\":\"call bash function\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/functions\\\/call-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\":\"How to Call a Function in Bash [7 Cases]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"name\":\"LinuxSimply\",\"description\":\"All About Linux\",\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linuxsimply.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\",\"name\":\"LinuxSimply\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"width\":355,\"height\":48,\"caption\":\"LinuxSimply\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/26b37b2c7517d2c8702472bc3986ef21\",\"name\":\"Md Zahidul Islam Laku\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Md-Zahidul-Islam-Laku-II-96x96.png\",\"caption\":\"Md Zahidul Islam Laku\"},\"description\":\"Hey, I'm Zahidul Islam Laku currently working as a Linux Content Developer Executive at SOFTEKO. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). I write articles on a variety of tech topics including Linux. Learning and writing on Linux is nothing but fun as it gives me more power on my machine. What can be more efficient than interacting with the Operating System without Graphical User Interface! Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/zahidlaku72\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/zahidlaku\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCnxMIaAb-nXO5XnMeEaNhpQ\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/laku\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Call a Function in Bash [7 Cases] - LinuxSimply","description":"Bash users must know how to call bash function. This article discusses different cases of calling a Bash function.","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\/call-function\/","og_locale":"en_US","og_type":"article","og_title":"How to Call a Function in Bash [7 Cases] - LinuxSimply","og_description":"Bash users must know how to call bash function. This article discusses different cases of calling a Bash function.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/zahidlaku72","article_published_time":"2024-02-04T10:28:33+00:00","article_modified_time":"2024-04-03T05:45:12+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/call-bash-function.png","type":"image\/png"}],"author":"Md Zahidul Islam Laku","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Md Zahidul Islam Laku","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/"},"author":{"name":"Md Zahidul Islam Laku","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/26b37b2c7517d2c8702472bc3986ef21"},"headline":"How to Call a Function in Bash [7 Cases]","datePublished":"2024-02-04T10:28:33+00:00","dateModified":"2024-04-03T05:45:12+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/"},"wordCount":1145,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/call-bash-function.png","keywords":["bash functions"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/","name":"How to Call a Function in Bash [7 Cases] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/call-bash-function.png","datePublished":"2024-02-04T10:28:33+00:00","dateModified":"2024-04-03T05:45:12+00:00","description":"Bash users must know how to call bash function. This article discusses different cases of calling a Bash function.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-function\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/call-bash-function.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/call-bash-function.png","width":400,"height":400,"caption":"call bash function"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/functions\/call-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":"How to Call a Function in Bash [7 Cases]"}]},{"@type":"WebSite","@id":"https:\/\/linuxsimply.com\/#website","url":"https:\/\/linuxsimply.com\/","name":"LinuxSimply","description":"All About Linux","publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxsimply.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linuxsimply.com\/#organization","name":"LinuxSimply","url":"https:\/\/linuxsimply.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","width":355,"height":48,"caption":"LinuxSimply"},"image":{"@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/26b37b2c7517d2c8702472bc3986ef21","name":"Md Zahidul Islam Laku","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Md-Zahidul-Islam-Laku-II-96x96.png","caption":"Md Zahidul Islam Laku"},"description":"Hey, I'm Zahidul Islam Laku currently working as a Linux Content Developer Executive at SOFTEKO. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). I write articles on a variety of tech topics including Linux. Learning and writing on Linux is nothing but fun as it gives me more power on my machine. What can be more efficient than interacting with the Operating System without Graphical User Interface! Read Full Bio","sameAs":["https:\/\/www.facebook.com\/zahidlaku72","https:\/\/www.linkedin.com\/in\/zahidlaku\/","https:\/\/www.youtube.com\/channel\/UCnxMIaAb-nXO5XnMeEaNhpQ"],"url":"https:\/\/linuxsimply.com\/author\/laku\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/35950","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\/314903"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=35950"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/35950\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/35959"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=35950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=35950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=35950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}