linux - csh脚本中的 undefined variable 错误

标签 linux bash shell

我在 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 可能是个好主意,因为您现有的代码可能已经在其中运行。

关于linux - csh脚本中的 undefined variable 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27813432/

相关文章:

c++ - 父进程的父进程 ID - Linux

bash - 将 globbing 的结果分配给 Bash 中的变量

bash - 程序化的 ngrok 隧道 URL

ios - 为 ios xcode 应用程序创建 bundle

linux - Shell脚本执行失败

linux - 如何使用静态 ip 而不是动态 ip 重新启动 wlan0?

linux - 在 Linux x86-64 上升级 SOS-BERLIN 作业调度程序困惑

c++ - 如何在 Linux 上的 C++ 中包含 <atomic>?

linux - 在 bash 进程替换完成输入后,如何继续发送到标准输入?

linux - 有没有Linux命令行环境的网站,可以练习命令?