O'Reilly logo

Linux in a Nutshell, 6th Edition by Robert Love, Stephen Figgins, Ellen Siever, Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required