Search code examples
stringif-statementvariablesfish

How to compare the contents of $var to a known string in fish shell


i am trying to get fish shell to figure out if a certain python virtual environment is loaded. I figured out that, if it is loaded, its path is saved in $VIRTUAL_ENV so i wrote the following.

 if  test [ "$VIRTUAL_ENV" != "home/user/Code/Python/Project/final project" ]
    source "/home/user/Code/Python/Final_Project/finalproject/bin/activate.fish"
else
    echo "Venv Running"
end

but it keeps spitting out that something is wrong without specifying what. The documentation isnt a huge help either, as i tried the [[ ]] notation for the test as well and cant find any specifics on variables

Does anyone know and can explain what i am doing wrong ?


Solution

  • [ is an alias for test, so don't use both: choose one of

    if test "$VIRTUAL_ENV" != "home/user/Code/Python/Project/final project" 
    

    or

    if [ "$VIRTUAL_ENV" != "home/user/Code/Python/Project/final project" ]