title: remote function with sudo is not giving expected results
body: <ol>
  <li>ssh oraauto works fine ( remote function sum_me )</li>
  </ol>
  <pre><code>2022-05-24 18:11:07 DEV oracle@HSTTT:~/user&gt; set -x
  
  2022-05-24 18:11:11 DEV oracle@HSTTT:~/user&gt; ssh oraauto@RMT_HST &quot;$(typeset -f sum_me) ; sum_me&quot;
  
  ++ typeset -f sum_me
  
  + ssh oraauto@RMT_HST 'sum_me ()
  
  {
  
      mem=48;
  
      if [[ `cat /proc/meminfo | grep -i memtotal | awk '\''{ print int($2/1024/1024)+1 }'\''` -eq $mem ]]; then
  
          echo &quot;memory test .. passed.&quot;;
  
      else
  
          echo &quot;memory test .. failed.&quot;;
  
      fi
  
  } ; sum_me'
  
  memory test .. passed.
  </code></pre>
  <ol start="2">
  <li>ssh oraauto , then sudo run as oracle fails</li>
  </ol>
  <pre><code>2022-05-24 18:11:18 DEV oracle@HSTTT:~/user&gt; ssh oraauto@RMT_HST &quot;sudo -u oracle ksh -c '$(typeset -f ); sum_me'&quot;
  
  ++ typeset -f
  
  + ssh oraauto@RMT_HST 'sudo -u oracle ksh -c '\''sum_me ()
  
  {
  
      mem=48;
  
      if [[ `cat /proc/meminfo | grep -i memtotal | awk '\''{ print int($2/1024/1024)+1 }'\''` -eq $mem ]]; then
  
          echo &quot;memory test .. passed.&quot;;
  
      else
  
          echo &quot;memory test .. failed.&quot;;
  
      fi
  
  }; sum_me'\'''
  
  bash: -c: line 3: syntax error near unexpected token `('
  
  bash: -c: line 3: `    if [[ `cat /proc/meminfo | grep -i memtotal | awk '{ print int($2/1024/1024)+1 }'` -eq $mem ]]; then'
  </code></pre>
  <ol start="3">
  <li>ssh oraauto works fine and sudo run as oracle works fine if simple date function.</li>
  </ol>
  <pre><code>2022-05-24 18:11:31 DEV oracle@HSTTT:~/user&gt; function sum_me { date; }
  
  2022-05-24 18:11:59 DEV oracle@HSTTT:~/user&gt; ssh oraauto@RMT_HST &quot;$(typeset -f sum_me) ; sum_me&quot;
  
  ++ typeset -f sum_me
  
  + ssh oraauto@RMT_HST 'sum_me ()
  
  {
  
      date
  
  } ; sum_me'
  
  Tue May 24 18:12:07 BST 2022
  
  2022-05-24 18:12:07 DEV oracle@HSTTT:~/user&gt;  ssh oraauto@RMT_HST &quot;sudo -u oracle ksh -c '$(typeset -f ); sum_me'&quot;
  
  ++ typeset -f
  
  + ssh oraauto@RMT_HST 'sudo -u oracle ksh -c '\''sum_me ()
  
  {
  
      date
  
  }; sum_me'\'''
  
  Tue May 24 18:12:13 BST 2022
  
  2022-05-24 18:12:13 DEV oracle@HSTTT:~/user&gt;
  </code></pre>
  <blockquote>
  <p>How to fix if function is defined as below</p>
  </blockquote>
  <pre><code>function sum_me {
  mem=48
  if [[ `cat /proc/meminfo | grep -i memtotal | awk '{ print int($2/1024/1024)+1 }'` -eq $mem ]]; then
  echo &quot;memory test .. passed.&quot;
  else
  echo &quot;memory test .. failed.&quot;
  fi
  }
  </code></pre>
  <ol>
  <li>ssh oraauto works fine ( remote function sum_me )</li>
  <li>ssh oraauto , then sudo run as oracle fails</li>
  <li>ssh oraauto works fine and sudo run as oracle works fine if simple date function.</li>
  <li>can some one help me to put workaround</li>
  <li>how to fix it</li>
  </ol>