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
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
You can use
if [[ -v user_lives_here ]] ; then
echo "variable is set"
else
echo "variable is not set"
fi