> ## Documentation Index
> Fetch the complete documentation index at: https://siriusbar.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Variables and Arguments

> Bash variables, script arguments, special parameters, and conditional syntax.

## Declaring Variables

One strict rule: no space around the `=` sign:

```bash theme={null}
name="Snake"     # correct
name = "Snake"   # wrong — bash tries to run "name" as a command
```

Variable names must also start with a letter or underscore and can contain only letters, digits and underscores:

```bash theme={null}
user_name="Snake"  # correct
2name="Snake"      # wrong
```

## 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 as `integer`:

```bash theme={null}
declare -i count=10
count=count+5
echo "$count"   # 15
```

Arithmetic contexts interpret values as numbers, while normal expansions produce text. This is why comparison operators are split into separate categories for strings and integers — we cover those in the next part.

## Special Variables

When we run a script, bash automatically populates these:

| Variable | Meaning                                                               |
| -------- | --------------------------------------------------------------------- |
| `$0`     | The name used to invoke the script or shell                           |
| `$#`     | Number of arguments passed                                            |
| `"$@"`   | All arguments, preserved as separate values                           |
| `$n`     | The n-th argument (`$1`, `$2`, etc.; use `${10}` above 9)             |
| `$$`     | PID of the main shell process (`BASHPID` is the current Bash process) |
| `$?`     | Exit status of the last command (`0` to `255`)                        |

`$?` 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:

```bash theme={null}
if [ "$value" -ge 10 ]   # correct
if ["$value" -ge 10]     # wrong
```

`[[ ]]` 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 `[[ ]]`.
