title: How to run functions and local resources over SSH in a shell script
body: <p>I have a shell script file like this:</p>
  
  <pre><code>#!/bin/bash
  
  CONF_FILE="/tmp/settings.conf" #settings.conf contains OS_NAME="Caine Linux"
  source $CONF_FILE
  
  display_os_name() { echo "My OS is:" $OS_NAME }
  
  #using the function locally works fine
  display_os_name
  #displays: My OS is: Caine Linux
  
  #using the function on the remote host doesn't work
  ssh user@host "$(declare -f); display_os_name"
  #displays: My OS is:
  </code></pre>
  
  <p>If I remove the  <code>-f</code> and I use just <code>ssh user@host "$(declare); display_os_name"</code> it works but displays these errors and warnings:</p>
  
  <pre><code>bash: line 10: BASHOPTS: readonly variable
  bash: line 18: BASH_VERSINFO: readonly variable
  bash: line 26: EUID: readonly variable
  bash: line 55: PPID: readonly variable
  bash: line 70: SHELLOPTS: readonly variable
  bash: line 76: UID: readonly variable
  </code></pre>
  
  <p>If I use <code>ssh user@host "$(declare); display_os_name &gt;/dev/null"</code> to suppress the warnings only the output of the function is suppressed (My OS is: Caine Linux), not the warnings.</p>
  
  <p>Is there a way to run local functions together with sourced local files on a remote SSH host?</p>