Search code examples
androidbashshellshlibvlc

Environmental variable is empty into shell script but not in shell


A shell script checks some of my environmental variables, but this code:

if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then
    echo "You must define ANDROID_NDK, ANDROID_SDK before starting."
    echo "They must point to your NDK and SDK directories.\n"
    exit 1
fi

prints out You must define ANDROID_NDK, ANDROID_SDK before starting. ....., rather if in a shell I write the command echo $ANDROID_SDK or echo $ANDROID_NDK it gives me the right result.


Solution

  • I answer my own question. What i was trying was to compile libvlc using osx instead of Linux. The problem was i don't know why but unzip was unable to extract the gradle.2.2.1.zip file so i thought i could do it using sudo but i was wrong because the execution of compile.sh was stopped in the code shown above because the enviromental variables are different for normal users and sudo. In the end i solved my problem extracting the gradle zip file by hand and executing this commands by myself instead of let the shell script execute them:

    cd gradle-${GRADLE_VERSION}
    
    ./bin/gradle wrapper
    checkfail "gradle: wrapper failed"
    
    ./gradlew -version
    checkfail "gradle: wrapper failed"
    cd ..
    mkdir -p gradle
    mv gradle-${GRADLE_VERSION}/gradle/wrapper/ gradle
    mv gradle-${GRADLE_VERSION}/gradlew .
    chmod +x gradlew
    rm -rf gradle-${GRADLE_VERSION}-all.zip gradle-${GRADLE_VERSION}
    

    Basically this script should work well on Linux but it is obvious that unzip has some problems with it on OSX.