csh脚本中的未定义变量错误

undefined variable error in csh script

我在 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.

请任何人提出我所缺少的东西?

C Shell csh 没有函数。它确实有别名,但那些更难写和读。例如,请参见此处:https://unix.stackexchange.com/questions/62032/error-converting-a-bash-function-to-a-csh-alias

简单地切换到 Bash 可能是个好主意,您现有的代码可能已经在其中工作了。