2012-04-04 89 views
0

我试图从bash脚本中取消激活pythonbrew。 当在shell中输入pythonbrew off可以正常工作。
在我的bash脚本pythonbrew off只是被忽略。 使用回音时,我得到:从bash脚本中取消激活pythonbrew

[email protected]:~/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 
} 

回答

0

事实证明,我不得不source $HOME/.bashrc/etc/bashrc因为功能不被导入到脚本。 我在我的〜/ .bashrc文件中有source $HOME/.bashrc/etc/bashrc,但据我所知,函数不会被导入到子进程中。