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



Comments


Add a Comment


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