Bash - Declare (Variable declaration and attribute)

Bash Liste Des Attaques Ovh

About

Declare variables and/or give them attributes.

Syntax

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

where:

  • names: If no names are given then display the values of variables.
  • p will display the attributes and values of each name. When -p is used, additional options are ignored.
  • F option inhibits the display of function definitions; only the function name and attributes are printed. 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. The -F option implies -f.

The following options can be used to restrict output to variables with the specified attribute or to give variables attributes:

  • -a Each name is an array variable.
  • -A declare the variables as an named associative array (not integer)
  • -f Use function names only.
  • -i The variable is treated as an integer; arithmetic evaluation is performed when the variable is assigned a value.
  • -r Make names readonly. See also the readonly builtin command. 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.

Using + instead of - turns off the attribute instead, with the exception that +a may not be used to destroy an array variable.

Scope

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.

Return 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
  • one of the names is not a valid shell variable name,
  • an attempt is made to turn off read-only 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.





Discover More
Bash Liste Des Attaques Ovh
Bash - (Environment) Variable

A variable is a parameters referenced by a name. parameter A variable has: a value and zero or more attributes (such as integer, ...). Attributes are assigned using the declare builtin command....
Bash Liste Des Attaques Ovh
Bash - Arithmetic Expression

arithmetic in bash part of compound expression . Counter Simple addition where let is the let command If the value of the expression is: non-zero, the return status is 0; otherwise ...
Bash Liste Des Attaques Ovh
Bash - Builtin Commands

builtin refers to: a builtin command. See or to the specific builtin command. See (useful when defining a function whose name is the same as a shell builtin) The builtin command execute the specified...
Bash Liste Des Attaques Ovh
Bash - Export (Builtin command)

The supplied names (variable or function) are marked for automatic export to the environment of subsequently executed commands. They are made available to all other command execution (script, ...)....
Bash Liste Des Attaques Ovh
Bash - local - Variable declaration in function - (Builtin)

local variable scoping declaration inside a block or a function. It is an error to use local when not within a function. For each argument, a local variable named name is created, and assigned value....
Bash Liste Des Attaques Ovh
How to use the Array Variable in Bash?

Bash provides a one-dimensional array variables. See also: When calling a function, quote the variable otherwise bash will not see the string as atomic. The separator is variable $IFS. There is: ...



Share this page:
Follow us:
Task Runner