Bootstrap FreeKB - Linux Commands - declare command
Linux Commands - declare command

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 846b6c in the box below so that we can be sure you are a human.