Linux Commands - declare command
by
Jeremy Canfield |
Updated: October 16 2023
| Linux Commands articles
declare can be used to determine if a variable or array has been defined. In this example, declare is used to determine if the foo variable has been defined.
declare -p foo
If the foo variable has not been defined, something like this should be returned.
bash: declare: foo: not found
If the foo variable has been defined, something like this should be returned. Two dashes (--) suggests that foo is a variable.
declare -- foo="bar"
If the foo array has been defined, something like this should be returned. -a means that foo is an array.
declare -a foo='([0]="bar")'
Did you find this article helpful?
If so, consider buying me a coffee over at