Linux Commands - declare command

by
Jeremy Canfield |
Updated: August 25 2024
| 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 foo has been defined.
declare -p foo
If foo has not been defined, something like this should be returned.
bash: declare: foo: not found
If foo has been defined, something like this should be returned. Two dashes (--) means that foo is a variable, not an array.
declare -- foo="bar"
-a means that foo is an array, not a variable.
declare -a foo='([0]="bar")'
Did you find this article helpful?
If so, consider buying me a coffee over at