Typing variables
declare weakly typed variables
Section titled “declare weakly typed variables”declare is an internal command of bash. (internal command use **help ** for displaying “manpage”). It is used to show and define variables or show function bodies.
Syntax: declare [options] [name[=value]]…
# options are used to define# an integerdeclare -i myIntegerdeclare -i anotherInt=10# an array with valuesdeclare -a anArray=( one two three)# an assoc Arraydeclare -A assocArray=( [element1]="something" [second]=anotherthing )# note that bash recognizes the string context within []
# some modifiers exist# uppercase contentdeclare -u big='this will be uppercase'# same for lower casedeclare -l small='THIS WILL BE LOWERCASE'
# readonly arraydeclare -ra constarray=( eternal true and unchangeable )
# export integer to environmentdeclare -xi importantInt=42You can use also the + which takes away the given attribute. Mostly useless, just for completness.
To display variables and/or functions there are some options too
# printing definded vars and functionsdeclare -f# restrict output to functions onlydeclare -F # if debugging prints line number and filename defined in too