Skip to Content
Linux in a Nutshell, 6th Edition
book

Linux in a Nutshell, 6th Edition

by Ellen Siever, Stephen Figgins, Robert Love, Arnold Robbins
September 2009
Beginner
942 pages
85h 34m
English
O'Reilly Media, Inc.
Content preview from Linux in a Nutshell, 6th Edition

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Unix in a Nutshell, 4th Edition

Unix in a Nutshell, 4th Edition

Arnold Robbins
Linux Under the Hood

Linux Under the Hood

Sander van Vugt
Linux Kernel in a Nutshell

Linux Kernel in a Nutshell

Greg Kroah-Hartman

Publisher Resources

ISBN: 9780596806088Errata Page