Declaring Variables
One strict rule: no space around the= sign:
Types (or the Lack of Them)
Bash variables are string-like by default, and Bash has no dedicated boolean type. But it also supports indexed arrays, associative arrays in Bash 4 and newer, and attributes such asinteger:
Special Variables
When we run a script, bash automatically populates these:$? is useful for debugging. We check it immediately after running a command to see its status. 0 means success; any non-zero value means failure.
[ ] vs [[ ]]
Both are used for conditionals but they are not the same thing.
[ ] are not just brackets — [ is a command, usually provided as a shell builtin, that behaves like the test command. So [ "$a" -eq 1 ] performs the same test as test "$a" -eq 1. The closing ] is the final argument expected by the [ command. This is why the spaces inside are required:
[[ ]] is Bash-specific conditional syntax. It handles pattern matching and compound expressions and avoids word splitting and pathname expansion. When we are writing specifically for Bash, we generally prefer [[ ]].