title: Environmental/global variables are not expanded in shell script
body: <p>I am trying to execute a function via SSH. I am able to do it after following <a href="https://stackoverflow.com/questions/22107610/shell-script-run-function-from-script-over-ssh">this post</a>.</p>
  
  <p>But if I have some global/environmental variable in the shell script those are not expanded. Here is the source code of the file to SSH node is not an option since its like a local copy.</p>
  
  <p>Ex i tried:</p>
  
  <pre><code>#!/bin/bash
  
  SKS="TYPO"
  
  fun2(){
  
      arg=$1
      echo $arg &gt;&gt; /tmp/a.o
      echo $SKS &gt;&gt; /tmp/a.o
  }
  
  fun1() {
  
      echo "SKSKSKSKS" &gt; /tmp/a.o
      fun2 "SPSP"
  
  }
  
  fun1
  
  SSH="ssh -4q -o StrictHostKeyChecking=no -o ConnectTimeout=10"
  $SSH &lt;ssh-host&gt; "$(typeset -f); fun1"
  </code></pre>
  
  <p>When I executed this script on the local node it gave me output as:</p>
  
  <pre><code>cat /tmp/a.o 
  SKSKSKSKS
  SPSP
  TYPO
  </code></pre>
  
  <p>but on the SSHed node its:</p>
  
  <pre><code>SKSKSKSKS
  SPSP
  </code></pre>
  
  <p>So here <code>$SKS</code> is not expanded on the SSHed node.</p>
  
  <p>Please help me to resolve this.</p>
  
  <p>Regards,
  Shridhar</p>