我在csh脚本中有一个函数,在这个函数中,我使用了一个来自一个文件的变量。但是当使用脚本时,它会为同一个变量抛出未定义的错误。我使用Linux。
我的代码
function init_remote_commands_to_use
{
# Test if the environment variable SSH_FOR_RCOMMANDS is present in .temip_config file,
# use secured on non secured rcommand depending on the result
if [ "$SSH_FOR_RCOMMANDS" != "" ]
then
if [ "$SSH_FOR_RCOMMANDS" = "ON" ]
then
# Check if the environment variable SSH_PATH is specified in .temip_config file
if [ "$SSH_PATH" != "" ]
then
SH_RCMD=$SSH_PATH
else
SH_RCMD=$SSH_CMD
fi
# Check if a ssh-agent is already running
if [ "$SSH_AGENT_PID" = "" ]
then
#Run ssh-agent for secured RCommands
eval `ssh-agent`
ssh-add
STARTEDBYME=YES
fi
else
if [ "$SSH_FOR_RCOMMANDS" = "OFF" ]
then
SH_RCMD=$RSH_CMD
else
echo "Please set the SSH_FOR_RCOMMANDS value to ON or OFF in the .temip_config file"
exit 1
fi
fi
else
SH_RCMD=$RSH_CMD
fi
}
下面是错误:
function: Command not found.
{: Command not found.
SSH_FOR_RCOMMANDS: Undefined variable.
请问有没有人告诉我我错过了什么?
2条答案
按热度按时间ds97pgxw1#
C Shell
csh
没有函数。它确实有别名,但那些更难写和读。例如,请参见此处:https://unix.stackexchange.com/questions/62032/error-converting-a-bash-function-to-a-csh-alias简单地切换到Bash可能是一个好主意,因为您现有的代码可能已经在工作了。
2sbarzqh2#
C Shell缺少一个函数特性。别名可以作为解决方法,但使用起来有些麻烦。更好的解决方法是使用
goto
和source
: