Skip to main content
deleted 6 characters in body
Source Link

I use the same technique for all variables in bash, and it works, e.g.:

[ ${foobar[@]foobar} ] && echo "foobar is set" || echo "foobar is unset"

outputs:

foobar is unset

whilst

foobar=( "val" "val2" )
[ ${foobar[@]foobar} ] && echo "foobar is set" || echo "foobar is unset"

outputs:

foobar is set

I use the same technique for all variables in bash, and it works, e.g.:

[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"

outputs:

foobar is unset

whilst

foobar=( "val" )
[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"

outputs:

foobar is set

I use the same technique for all variables in bash, and it works, e.g.:

[ ${foobar} ] && echo "foobar is set" || echo "foobar is unset"

outputs:

foobar is unset

whilst

foobar=( "val" "val2" )
[ ${foobar} ] && echo "foobar is set" || echo "foobar is unset"

outputs:

foobar is set
Added code formatting
Source Link
Thor
  • 17.5k
  • 3
  • 55
  • 71

I use the same technique for all variables in bash, and it works, e.g.:

[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"

[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"

foobar is unsetoutputs:

foobar=( "val" )

foobar is unset

[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"whilst

foobar=( "val" )
[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"

foobar is setoutputs:

foobar is set

I use the same technique for all variables in bash, and it works:

[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"

foobar is unset

foobar=( "val" )

[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"

foobar is set

I use the same technique for all variables in bash, and it works, e.g.:

[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"

outputs:

foobar is unset

whilst

foobar=( "val" )
[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"

outputs:

foobar is set
Source Link

I use the same technique for all variables in bash, and it works:

[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"

foobar is unset

foobar=( "val" )

[ ${foobar[@]} ] && echo "foobar is set" || echo "foobar is unset"

foobar is set