Recherche…


déclarer des variables faiblement typées

declare est une commande interne de bash. (commande interne utiliser l' aide pour afficher "manpage"). Il est utilisé pour afficher et définir des variables ou afficher des corps de fonctions.

Syntaxe: declare [options] [nom [= valeur]] ...

# options are used to define
# an integer
declare -i myInteger
declare -i anotherInt=10
# an array with values
declare -a anArray=( one two three)
# an assoc Array
declare -A assocArray=( [element1]="something" [second]=anotherthing )
# note that bash recognizes the string context within []

# some modifiers exist
# uppercase content
declare -u big='this will be uppercase'
# same for lower case
declare -l small='THIS WILL BE LOWERCASE'

# readonly array
declare -ra constarray=( eternal true and unchangeable )

# export integer to environment
declare -xi importantInt=42

Vous pouvez aussi utiliser le + qui supprime l'attribut donné. Surtout inutile, juste pour la complétude.

Pour afficher des variables et / ou des fonctions, il existe également des options

# printing definded vars and functions
declare -f
# restrict output to functions only
declare -F # if debugging prints line number and filename defined in too


Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow