> ## 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 Parameter Transformation

The `@` symbol in Bash is a special parameter and array subscript that expands to all positional parameters or all elements of an array. Its primary mechanical function is to handle multi-word arguments and array elements, treating each expanded element as a discrete, individual word when evaluated in contexts subject to word splitting.

## Positional Parameters Expansion

When used as a standalone special parameter, `@` references the arguments passed to the current shell or function. Its behavior is strictly dictated by whether it is enclosed in double quotes and the evaluation context.

```bash theme={"dark"}
$@
"$@"
```

* **Unquoted (`$@`)**: Expands to all positional parameters starting from `$1`. The shell subsequently subjects the expanded result to word splitting (based on `IFS`) and pathname expansion (globbing).
* **Double-quoted (`"$@"`)**: In contexts where word splitting is performed (such as command arguments), it expands each positional parameter into a separate, distinct word, bypassing word splitting and pathname expansion. Mechanically, it is equivalent to `"$1" "$2" ... "$N"`. However, in contexts where word splitting is *not* performed (such as scalar variable assignments like `var="$@"` or inside `[[ ]]` conditional tests), `"$@"` does not expand into separate words. Instead, it flattens the elements into a single string separated by a space, regardless of the value of `IFS`.

## Array Element Expansion

When applied as a subscript within curly braces, `@` targets the elements of an array.

```bash theme={"dark"}
${array_name[@]}
"${array_name[@]}"
```

* **Unquoted (`${array_name[@]}`)**: Expands all values in an indexed or associative array, subject to standard word splitting and globbing.
* **Double-quoted (`"${array_name[@]}"`)**: Expands each array element as a separate word (in word-splitting contexts), preserving the exact string boundaries of each element as they were originally assigned.

## Array Key/Index Expansion

By prepending the parameter name with the `!` operator inside the curly braces, `@` evaluates to the indices (for indexed arrays) or keys (for associative arrays) rather than the values.

```bash theme={"dark"}
${!array_name[@]}
"${!array_name[@]}"
```

## Element Counting

When combined with the `#` length operator, `@` returns the total number of elements rather than the elements themselves.

```bash theme={"dark"}
${#@}              # Returns the count of positional parameters
${#array_name[@]}  # Returns the count of elements in the specified array
```

## Parameter Slicing

The `@` operator supports offset and length expansion to extract a contiguous subset of elements.

```bash theme={"dark"}
${@:offset:length}
"${array_name[@]:offset:length}"
```

This operation is strictly valid only for positional parameters and **indexed** arrays. Applying substring expansion (slicing) to an associative array produces undefined results or errors. The syntax expands to `length` elements starting from the specified `offset`. If `length` is omitted, it expands to all elements from the `offset` to the end of the array or positional parameters.

## Pattern Substitution

The `@` operator allows search and replace operations to be mapped across all elements of an array or all positional parameters simultaneously.

```bash theme={"dark"}
${@/pattern/replacement}
"${array_name[@]/pattern/replacement}"
```

The shell applies the pattern substitution to each element individually. When double-quoted in a word-splitting context, the discrete word boundaries of each modified element are preserved.

## Technical Distinction: `@` vs `*`

The `@` operator is frequently contrasted with the `*` operator. Their mechanical differences are exposed during double-quoted expansion and when handling empty parameter lists:

```bash theme={"dark"}
"$@"  # Expands to N discrete words: "$1" "$2" "$3" (in word-splitting contexts)
"$*"  # Expands to 1 single word, delimited by the first character of IFS: "$1c$2c$3"
```

* **Empty Parameters**: If there are zero positional parameters (or when an array is empty), `"$@"` expands to nothing (zero words). In contrast, `"$*"` expands to a single empty string (one word).
* **Delimiters and Non-Word-Splitting Contexts**: In contexts where word splitting is performed, `"$@"` consistently maintains the original token boundaries and discrete element separation regardless of the `IFS` state. In contexts where word splitting is *not* performed, `"$@"` flattens elements using a space as the delimiter, whereas `"$*"` flattens elements using the first character of `IFS`.

<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>
