Python Data Types, Typeset & Declare Attributes
In Bash, all variables are fundamentally stored as strings. However, the `declare` (or `typeset`) builtin allows assigning specific type attributes: integer arithmetic (`-i`), read-only constants (`-r`), exported environment variables (`-x`), indexed arrays (`-a`), and associative key-value maps (`-A`).
"By default, Bash treats every variable like a plain slip of paper (string). Using `declare` stamps a specialized badge on the paper (e.g. calculator for integer, padlock for readonly)."
Deep Dive: How It Works
declare Flags: `-i` (integer: enables arithmetic without `$(( ))`), `-r` (readonly: immutable), `-a` (indexed array), `-A` (associative array / hash map), `-x` (export to subshells), `-p` (print variable attributes and values).
Integer Evaluation: With `declare -i count=10; count+=5`, `count` evaluates to `15` instead of string `"105"`.
Inspecting Variables: `declare -p VAR_NAME` outputs the exact declaration statement recreating the variable.
Syntax Blueprint
declare -i age=25 # Integer variable declare -r VERSION="1.0" # Read-only constant declare -a list=(1 2 3) # Indexed array declare -A config=(["env"]="prod") # Associative map
Use declare to enforce typing and structure for complex script state.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using `declare -A` in legacy Bash 3.2 (default on macOS).Why it happens: Associative arrays require Bash 4.0 or newer.
How to fix: Ensure shebang uses `#!/usr/bin/env bash` and install modern Bash via Homebrew on Mac.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Declare an Integer Variable
Declare an integer variable `declare -i total=50`.
Add 25 to it with `total=total+25`.
Echo "Total: $total".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.