Skip to main content
added 1 character in body
Source Link

bash function that works for both scalar and array types:

definition

has_declare() { # check if variable is set at all local "$@" # inject 'name' argument in local scope &>/dev/null declare -p "$name" # return 0 when var is present } 

invocation

if has_declare name="vars_name" ; then echo "variable present: vars_name=$vars_name" fi 

bash function that works for both scalar and array types:

definition

has_declare() { # check if variable is set at all local "$@" # inject 'name' argument in local scope &>/dev/null declare -p "$name" # return 0 when var is present } 

invocation

if has_declare name="vars_name" ; then echo "variable present: vars_name=$vars_name" fi 

bash function that works for both scalar and array types:

definition

has_declare() { # check if variable is set at all local "$@" # inject 'name' argument in local scope &>/dev/null declare -p "$name" # return 0 when var is present } 

invocation

if has_declare name="vars_name" ; then echo "variable present: vars_name=$vars_name" fi 
Source Link

bash function that works for both scalar and array types:

definition

has_declare() { # check if variable is set at all local "$@" # inject 'name' argument in local scope &>/dev/null declare -p "$name" # return 0 when var is present } 

invocation

if has_declare name="vars_name" ; then echo "variable present: vars_name=$vars_name" fi