我有一个这样的 shell 脚本文件:#!/bin/bashCONF_FILE=\'/tmp/settings.conf\' #settings.conf contains OS_NAME=\'Caine Linux\'source $CONF_FILEdisplay_os_name() { echo \'My OS is:\' $OS_NAME }...
我有一个像这样的 shell 脚本文件:
#!/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:
如果我删除 -f
并且只使用 ssh user@host "$(declare); display_os_name"
,它可以工作,但会显示这些错误和警告:
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
如果我使用 ssh user@host "$(declare); display_os_name >/dev/null"
抑制警告,则仅抑制函数的输出(我的操作系统是:Caine Linux),而不是警告。
有没有办法在远程 SSH 主机上将本地函数与源本地文件一起运行?