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
  • 9,608
  • 6
  • 34
  • 56
bluethundr
  • 1,005
  • 17
  • 68
  • 141

1 Answers1

1

You can use

if [[ -v user_lives_here ]]  ; then
    echo "variable is set"
else
    echo "variable is not set"
fi
hek2mgl
  • 152,036
  • 28
  • 249
  • 266