Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (6.1k points)

I am having .sh script and it contains "if" in it:

 if [ -z "$SOME_LIB" ]; then

    echo "Environment variable SOME_LIB is needed!"

    exit 1

    fi

Whenever I type “printenv” it displays that “SOME_LIB” contains the value "/usr/local/lib/python2.6 ". That path is correct. But the moment I run that .sh file from the terminal it displays: "Environment variable SOME_LIB is needed!"

How to run it properly?

1 Answer

0 votes
by (11.7k points)

There can be a case that variables are not set properly in the script so you can add printenv before your if command in the script.

You can also debug the script using set -x or run it using bash -x to make it display the value of the variable while checking.

Want to get in-depth knowledge of Linux, check out this Linux course from Intellipaat.

Related questions

Browse Categories

...