declare

Declare shell variables with types and attributes.

low risk

interactive breakdown — edit the command and press Explain
$ 
What it does

declare sets variable attributes: -i for integers, -a for arrays, -A for associative arrays (hash maps), -r for read-only, -x for export. Enables type-checking and structured data in bash scripts.

Common flags
FlagMeaning
-i --integerTreat variable as integer (arithmetic only)
-a --arrayIndexed array
-A --assocAssociative array (hash map)
-r --readonlyRead-only variable
-x --exportExport to environment
-p --printPrint variable declaration
Examples
declare -A config; config[host]='localhost'; config[port]=5432Create an associative array (hash map) · explain & risk-check →
declare -i count=0; count+=1Integer variable with arithmetic · explain & risk-check →
declare -r VERSION='1.2.3'Read-only constant · explain & risk-check →
declare -p myvarPrint variable declaration for debugging · explain & risk-check →
Pro tip

Use `declare -A` for config maps in bash scripts: store key-value pairs without external tools. Iterate with `for key in "${!map[@]}"; do echo "$key=${map[$key]}"; done`

Related
export set bash
Open the full explainer →More in Shell & Scripting

Reference text is hand-written and may be incomplete — check man declare for your version. Test destructive commands on a non-production system first.