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

The `+` operator in Bash is a context-dependent token whose behavior is strictly dictated by the syntactic construct in which it is evaluated. It functions as an arithmetic operator, an assignment/append operator, a parameter expansion modifier, an attribute toggler, a directory stack index indicator, and a pattern-matching quantifier.

## Arithmetic Evaluation

Within arithmetic expansion, the `+` token functions as a standard binary addition operator or a unary positive operator. Bash arithmetic is restricted to integers; floating-point operations are not natively supported.

**Syntax:**

```bash theme={"dark"}
$(( operand1 + operand2 ))
let "result = operand1 + operand2"
$(( +operand ))
```

## Append and Assignment Operator (`+=`)

The `+=` token is a compound assignment operator that performs context-dependent appending or arithmetic addition.

**Syntax:**

```bash theme={"dark"}
variable+="string"
array+=(element1 element2)
(( variable += integer ))
```

* **String Concatenation:** When applied to a standard scalar variable, it appends the right-hand string to the existing value.
* **Array Appending:** When applied to an indexed or associative array using compound assignment syntax `()`, it appends new elements to the array.
* **Arithmetic Assignment:** Within an arithmetic evaluation context `(( ))` or `let`, it performs integer addition and assigns the computed sum back to the variable.
* **Integer Attribute Assignment:** If a scalar variable has the integer attribute set (via `declare -i`), using `+=` on it performs arithmetic addition rather than string concatenation, even outside of an explicit arithmetic context like `(( ))` or `let`.

## Parameter Expansion (Alternate Value)

In brace-enclosed parameter expansion, the `+` operator tests the state of a variable and substitutes an alternate string based on whether the variable is set or null. It does not modify the original variable.

**Syntax:**

```bash theme={"dark"}
${parameter+word}
${parameter:+word}
```

* **`${parameter+word}`**: If `parameter` is declared/set (even if its value is null), the expansion evaluates to `word`. If unset, it evaluates to nothing.
* **`${parameter:+word}`**: The inclusion of the colon (`:`) enforces a strict non-null test. If `parameter` is set *and not null*, it evaluates to `word`. If unset or null, it evaluates to nothing.

## Shell Option and Attribute Toggling

When used as an argument prefix with the `set` builtin or variable declaration builtins (`declare`, `typeset`, `local`), the `+` operator disables shell options or removes variable attributes. This is the inverse of standard POSIX conventions where `-` enables options or sets attributes.

*Note: The `export` builtin does not accept `+` flags to remove attributes. To remove the export attribute from a variable, you must use `export -n` or `declare +x`.*

**Syntax:**

```bash theme={"dark"}
set +[short-option-flag]
set +o [long-option-name]
declare +[attribute-flag] variable_name
typeset +[attribute-flag] variable_name
```

## Directory Stack Indexing

Builtins that manipulate the directory stack (`pushd`, `popd`, `dirs`) use the `+` prefix followed by an integer to reference a specific directory index. The `+N` notation specifies the Nth directory from the left of the directory stack, starting with zero.

**Syntax:**

```bash theme={"dark"}
pushd +N
popd +N
dirs +N
```

## Extended Globbing Quantifier

When the `extglob` shell option is enabled (`shopt -s extglob`), the `+` operator functions as a pattern-matching quantifier. It evaluates strings against a delimited list of patterns.

**Syntax:**

```bash theme={"dark"}
+(pattern1|pattern2|...)
```

This construct matches one or more occurrences of any of the patterns specified within the parentheses.

## Regular Expression Quantifier

Within the conditional test construct `[[ ]]` utilizing the `=~` binary operator, the right-hand side is evaluated as a POSIX Extended Regular Expression (ERE). Here, `+` retains its standard regex definition.

**Syntax:**

```bash theme={"dark"}
[[ $string =~ pattern+ ]]
```

The `+` quantifies the preceding regex token, requiring it to match one or more times consecutively.

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