Question

I'm trying to deactivate pythonbrew from a bash script. When inside the shell typing pythonbrew off works correctly.
In my bash script pythonbrew off is just ignored. when using echo I get:

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

Calling the function causes the program to exit without printing the failure message.
Here's the function:

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
}
Was it helpful?

Solution

It turns out that I had to source $HOME/.bashrc/etc/bashrc since functions are not imported to the script. I have source $HOME/.bashrc/etc/bashrc in my ~/.bashrc file but as far as I understand the functions are not imported to a sub process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top