我正在尝试从bash脚本中停用pythonbrew。在shell中,键入pythonbrew off可以正常工作。
在我的bash脚本中,pythonbrew off被忽略了。当使用echo时,我得到:
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
}发布于 2012-04-06 15:16:31
事实证明,我必须使用source $HOME/.bashrc/etc/bashrc,因为函数没有导入到脚本中。我的~/.bashrc文件中有source $HOME/.bashrc/etc/bashrc,但据我所知,这些函数没有导入到子进程中。
https://stackoverflow.com/questions/10020004
复制相似问题