declare - Declare variables and set attributes

Synopsis

declare [ -Eilrux ] name [=value] ...

declare [ +Eilrux ] name [=value] ...

declare -fF [ name ... ]

declare -p name ...

declare

Description

The declare utility declares variables, assigns values to variables, sets or unsets attributes for variables, and displays the definitions for shell functions. If used in a shell function, declare makes the variable name local to the function.

In the first synopsis form, declare declares a variable name and optionally assigns it the specified value. If an option is specified, the corresponding attribute is turned on for the variable.

In the second synopsis form, declare declares a variable name and optionally assigns it the specified value. If an option is specified, the corresponding attribute is turned off for the variable.

In the third synopsis form, declare displays the names and definitions for all shell functions if no names are specified or the shell functions specified by name.

In the fourth synopsis form, declare displays the attributes and value of the variables specified by name in a re-enterable format.

In the fifth synopsis form, declare displays the names and values of all variables.

Options

-E
Set the floating point attribute for the variable. On assignments to the variable the value is evaluated as a floating point number.
-f
Display the names and definitions of shell functions.
-F
Display the names of shell functions.
-i
Set the integer attribute for the variable. On assignments to the variable the value is evaluated as an integer number.
-l
Set the lowercase attribute for the variable. On assignments to the variable the value is set to lowercase characters.
-p
Display each variable in a re-enterable format.
-r
Set the read-only attribute for the variable. The variable cannot have its value changed by a subsequent assignment and cannot be unset. If a value is also specified, the value of the variable is updated before setting the read-only attribute.
-u
Set the uppercase attribute for the variable. On assignments to the variable the value is set to uppercase characters.
-x
Set the export attribute for the variable. The variable is automatically placed in the environment of subsequently executed commands.

Operands

Each name must be a valid shell variable name.

Exit Status

Related information