Name
declare
Synopsis
declare [options
] [name
[=value
]] typeset [options
] [name
[=value
]]
Declare variables and manage their attributes. In function bodies, variables are local, as if declared with the local command.
Options
- -a
Each name is an indexed array variable.
- -A
Each name is an associative array variable.
- -f
Each name is a function.
- -F
For functions, print just the function name and attributes, not the function definition (body). Implies -f.
- -i
Each variable is an integer; in an assignment, the value is evaluated as an arithmetic expression.
- -l
Assign all values as lowercase only; convert uppercase to lowercase.
- -p
With no names, print all variables and their values. With names, print the names, attributes, and values of the given variables. Used with -f, print all function names and attributes. This option causes all other options to be ignored.
- -r
Mark names as read-only. Subsequent assignments will fail.
- -t
Apply the trace attribute to each name. Traced functions inherit the DEBUG and RETURN traps from the shell. This attribute has no meaning for variables.
- -u
Assign all values as uppercase only; convert lowercase to uppercase.
- -x
Mark names for export into the environment of child processes.
With a + instead of a -, the given attribute is disabled. With no variable names, all variables having the given attribute(s) are printed in a form that can be reread as input to the shell.
Examples
$declare -i val
Make val an integer $val=4+7
Evaluate value $echo $val
Show result 11 $declare -r z=42
Make ...
Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.