0

I want to to execute an if statement a variable is set. I'm using bash.

Can I just use this statement:

if  [[ "$user_lives_here" ]]; then

Or is it better to use something like:

if  [[ ! -z "$user_lives_here" ]]; then
0

1 Answer 1

1

You can use

if [[ -v user_lives_here ]]  ; then
    echo "variable is set"
else
    echo "variable is not set"
fi
Sign up to request clarification or add additional context in comments.

1 Comment

...if you have Bash 4.2 or newer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.