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

# Bash Positional Parameter

Positional parameters are a series of special, dynamically assigned variables in Bash that store the arguments passed to a script, shell, or function upon invocation. They are numerically indexed, read-only via standard assignment, and automatically populated by the shell's parser during execution.

## Syntax and Indexing

Positional parameters are referenced using digits. Single-digit parameters can be referenced directly with the `$` prefix. Multi-digit parameters strictly require curly braces `{}` to prevent the shell from misinterpreting the variable name.

```bash theme={"dark"}
$0       # The name of the calling script or shell (special parameter, not strictly positional)
$1       # The first positional parameter
$2       # The second positional parameter
...
$9       # The ninth positional parameter
${10}    # The tenth positional parameter (braces are mandatory)
${11}    # The eleventh positional parameter
```

## Aggregate Special Parameters

Bash provides specific special parameters to evaluate or expand the entire array of positional parameters at once:

```bash theme={"dark"}
$#       # Expands to the decimal count of positional parameters currently set.
$*       # Expands to all positional parameters.
$@       # Expands to all positional parameters.
```

### Expansion Behavior: `"$*"` vs `"$@"`

When unquoted, `$*` and `$@` behave identically, expanding to the list of arguments subject to standard word splitting and pathname expansion. When enclosed in double quotes, their parsing behavior diverges:

* `"$*"` expands to a **single string** containing all parameters, separated by the first character of the `IFS` (Internal Field Separator) variable. It evaluates as: `"$1c$2c$3"` (where `c` is the first character of `IFS`). If `IFS` is unset, the parameters are separated by spaces. If `IFS` is null (e.g., `IFS=`), the parameters are joined without any intervening separators.
* `"$@"` expands to **separate strings** for each positional parameter. It evaluates as: `"$1" "$2" "$3"`. This is the standard mechanism for preserving internal whitespace and exact argument boundaries.

## Parameter Manipulation

Because positional parameters cannot be reassigned using standard variable assignment syntax, Bash provides built-in commands to manipulate them. In Bash, variable names must begin with an alphabetic character or an underscore. Because a digit like `1` is not a valid identifier for assignment, the parser treats an expression like `1="value"` as a command execution. This results in a `command not found` error (e.g., `bash: 1=value: command not found`), rather than a syntax error.

### The `shift` Builtin

The `shift [n]` command shifts the positional parameters to the left by `n` positions (where `n` defaults to 1). The parameter at `$1` is discarded, `$2` becomes `$1`, and `$#` is decremented accordingly. If `n` is greater than the current number of positional parameters (`$#`), the command fails (returns a non-zero exit status) and the positional parameters remain completely unchanged.

```bash theme={"dark"}

# Initial state: $1="alpha", $2="beta", $3="gamma", $#=3
shift 1

# Resulting state: $1="beta", $2="gamma", $#=2
```

*Note: The `$0` parameter is immutable and is never affected by `shift`.*

### The `set` Builtin

The `set` builtin can be used to completely overwrite the current context's positional parameters. Using the `--` delimiter ensures that subsequent strings are treated strictly as positional parameters, even if they begin with a hyphen.

```bash theme={"dark"}

# Clears existing parameters and assigns new ones
set -- "new_arg1" "new_arg2" "new_arg3"


# Resulting state: $1="new_arg1", $2="new_arg2", $3="new_arg3", $#=3
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Bash Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
