Bash.Builtin.Declare (Bash v0.6.0)

Copy Markdown View Source

declare [-afFirtx] [-p] [name[=value] ...]

Declare variables and/or give them attributes. If no NAMEs are given, then display the values of variables instead. The -p option will display the attributes and values of each NAME.

The flags are:

  • -a - to make NAMEs indexed arrays
  • -A - to make NAMEs associative arrays
  • -f - to select from among function names only
  • -F - to display function names without definitions
  • -i - to make NAMEs have the "integer" attribute
  • -r - to make NAMEs readonly
  • -x - to make NAMEs export
  • -p - display variable declarations

Variables with the integer attribute have arithmetic evaluation (see let) done when the variable is assigned to.

When displaying values of variables, -f displays a function's name and definition. The -F option restricts the display to function name only.

Using + instead of - turns off the given attribute instead. When used in a function, makes NAMEs local, as with the local command.

Reference: https://cgit.git.savannah.gnu.org/cgit/bash.git/plain/builtins/declare.def?h=bash-5.3