title: Export a variable from the function declare onto another script
body: <p>So, I have the following variables (I am only showing a few of them as there are hundreds..)</p>
  <pre><code>&gt; cat variables.txt 
  
  # Saved variables from the script (This file is only for illustration purposes)
  
  br_int0_srxa = br-int0-xa
  br_int1_srxa = br-int1-xa
  br_int2_srxa = br-int2-xa
  {...}
  br_int0_srxb = br-int0-xb
  {...}
  br_wan3_srxd = br-wan3-xd
  {...}
  </code></pre>
  <p>Each of those variables were set using the declare function <code>declare br${H}=${br_name}</code></p>
  <p><strong>a.sh</strong></p>
  <p>Where:</p>
  <pre><code># This is script a.sh
  
  my_child_function ()
  
  {
  # i= Numbers from 0-7
  # f= Alternating letters (a-d)
  # br_name = the respective name given (This changes on each loop)
  
  # THIS SCRIPT IS IN A LOOP, THAT HOW I GET DIFFERENT VARIABLES
  # {START OF LOOP}
  H=_int{$i}_srx{$f}
  declare b{$H}=${br_name}
  export b{$H}=${br_name} ## &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; I tried using export to &quot;export&quot; the variable
  
  
  # Saving the variable into the variables.txt file for illustration purposes
  results= b{$H}=${br_name}
  
  # Saving the result into variables.txt
  echo $results &gt;&gt; variables.txt
  
  # {END OF LOOP}
  
  var_name=b{$H} # &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; Only renaming the declared variable
  echo ${!var_name}
  }
  </code></pre>
  <hr />
  <p>The previous script runs when I run main.sh:</p>
  <p><strong>main.sh</strong></p>
  <pre><code>my_script () 
  {
   my_child_function
   sleep 1
   my_child_function2
  }
  
  . a.sh
  . b.sh
  </code></pre>
  <hr />
  <p><strong>b.sh</strong></p>
  <pre><code>my_child_function2 ()
  {
    echo &quot;This is script b.sh&quot;
    echo ${!var_name}
    echo &quot;End of script b.sh&quot;
  }
  
  </code></pre>
  <pre><code># Example of output when I run ./main.sh
  br-int0-xa
  This is script b.sh
  
  End of script b.sh
  </code></pre>
  <p>As you can see I cannot export the variable that was saved using &quot;declare&quot; I tried adding the <code>export</code> function and nothing. I cannot use the variables stored from <code>a.sh</code> onto <code>b.sh</code></p>