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
Ronan Boiteau
  • 8,910
  • 6
  • 33
  • 52
bluethundr
  • 383
  • 14
  • 49
  • 115

1 Answers1

1

You can use

if [[ -v user_lives_here ]]  ; then
    echo "variable is set"
else
    echo "variable is not set"
fi
hek2mgl
  • 143,113
  • 25
  • 227
  • 253