Exported function not found in another script
<p>I am trying to write a unix script that has the structure below. Basically, I want to have a "Library" script of functions that I use all the time, and export all the functions using <code>export -f functionName</code>.  The actual script using the library functions would first run the library script to perform the export commands and would then theoretically have access to the functions just exported.  However, this does not work as shown by the error.  Both scripts have been <code>chmod 777</code>'ed for testing.  I am literally trying these examples below.  These are not substitutes for some prod code somewhere. I copied and pasted what I am trying. </p>

<p>LibraryFunctions.sh:</p>

<pre><code>#!/bin/bash

function getHelloWorldString() {
    echo "Hello World"
} 
export -f getHelloWorldString
</code></pre>

<p>TestLibraryFunctions.sh</p>

<pre><code>#!/bin/bash

./LibraryFunctions.sh

function testExportedHelloWorld () {
    echo $(getHelloWorldString)
}
testExportedHelloWorld
</code></pre>

<p>Result:</p>

<pre><code>me@myHost:~/testDir $ ./TestLibraryFunctions.sh
./TestLibraryFunctions.sh: line 6: getHelloWorldString: command not found
</code></pre>

<p><strong>Edit: Solution that worked for me:</strong></p>

<p>Removed <code>export -f getHelloWorldString</code> from LibraryFunctions.sh</p>

<p>Removed <code>./LibraryFunctions.sh</code>from TestLibraryFunctions.sh</p>

<p>Added <code>source LibraryFunctions.sh</code>from TestLibraryFunctions.sh at the top</p>

<p>-------  New files ------:</p>

<p>LibraryFunctions.sh:</p>

<pre><code>#!/bin/bash

function getHelloWorldString() {
    echo "Hello World"
} 
</code></pre>

<p>TestLibraryFunctions.sh</p>

<pre><code>#!/bin/bash

source LibraryFunctions.sh

function testExportedHelloWorld () {
    echo $(getHelloWorldString)
}
testExportedHelloWorld
</code></pre>

<p>Thanks all!</p>