linux - getting error with bash script for env variables -


this question has answer here:

i using conditional in bash script

if [ $use_test -eq 1 ]; echo "hello" fi 

where pass use_test environment variables.

if pass env variable shell executes ok if don't have variable this

[: -eq: unexpected operator 

how can fix that

this 1 of matter quotes important; when $use_test not defined, statement expands to:

if [ -eq 1 ]; 

the common fix:

if [ "$use_test" -eq 1 ]; 

...though imply switching string comparison, because -eq break empty string:

if [ "$use_test" = 1 ]; 

but may consider using [[ (which bash builtin) or ${use_test:-0} (which specifies default value).


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -