0

我正在尝试从 bash 脚本中停用 pythonbrew。在 shell 内键入时pythonbrew off可以正常工作。
在我的 bash 脚本pythonbrew off中只是被忽略了。使用回声时,我得到:

omer@omer-VirtualBox:~/Projects/devenv$ echo $("pythonbrew off")
pythonbrew off: command not found

调用该函数会导致程序退出而不打印失败消息。
这是功能:

function deactivate_pythonbrew()
{
    echo "Detecting whether Pythonbrew is installed."
    pythonbrew_version="$(pythonbrew --version 2>&1)"
    if [ -n $pythonbrew_version ]
    then
        echo "Pythonbrew $pythonbrew_version found."

        if [ -n $pythonbrew ]
        then
            pythonbrew off || echo "Failed to deactivate pythonbrew. Aborting." && exit $?
        else
            echo "Pythonbrew is inactive. Skipping."
        fi
    else
        echo "Pythonbrew is not installed. Skipping."
    fi
}
4

1 回答 1

0

事实证明,我必须这样做,source $HOME/.bashrc/etc/bashrc因为函数没有导入到脚本中。我source $HOME/.bashrc/etc/bashrc的 ~/.bashrc 文件中有,但据我了解,这些函数并未导入到子进程中。

于 2012-04-06T07:16:31.317 回答