declare

Declare variable(s) and/or give them attributes.

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

typeset [-afFirtx] [-p] [name[=value] ...] Key -a Each name is an array variable.
-f Use function names only. -F Inhibit the display of function definitions (implies -f) only the function name and attributes are printed.
-i The variable is treated as an integer; arithmetic evaluation (see ARITHMETIC EVALUATION) is performed when the variable is assigned a value.
-r Make names readonly. These names cannot then be assigned values by subsequent assignment
statements or unset.
-t Give each name the trace attribute. Traced functions inherit the DEBUG and RETURN traps from the calling shell. The trace attribute has no special meaning for variables.
-x Mark names for export to subsequent commands via the environment. -p Display the attributes and values of each name. When -p is used, additional options are ignored.

If no names are given then display the values of variables.

Using `+' instead of `-' turns off the attribute instead, e.g. +i means don't treat as an integer - one exception is that +a may not be used to destroy an array variable.

When used in a function, makes each name local, as with the local command.

If a variable name is followed by =value, the value of the variable is set to value

The return value is 0 unless an invalid option is encountered, an attempt is made to define a function using ``-f foo=bar'', an attempt is made to assign a value to a readonly variable, an attempt is made to assign a value to an array variable without using the compound assignment syntax (see Arrays above), one of the names is not a valid shell variable name, an attempt is made to turn off readonly status for a readonly variable, an attempt is made to turn off array status for an array variable, or an attempt is made to display a non-existent function with -f.

If the extdebug shell option is enabled using shopt, the source file name and line number where the function is defined are displayed as well.

declare is a bash builtin command

“I have nothing to declare but my genius” - Oscar Wilde

Related:

for - Expand words, and execute commands
while - Loop to execute commands
until - Loop to execute commands


© Copyright SS64.com 1999-2013
Some rights reserved