> ## 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 Unary Plus

The `+` operator in Bash is a context-dependent token whose behavior is dictated by the syntactic construct in which it is evaluated. It functions primarily as an arithmetic addition and unary operator, a parameter expansion modifier, an extended globbing quantifier, a regular expression quantifier, a string or array concatenation operator, and a shell option or variable attribute toggle.

## Arithmetic Evaluation

Within arithmetic expansion contexts, `+` functions as a standard binary addition operator for integer arithmetic. Bash does not natively support floating-point arithmetic; therefore, operands are strictly evaluated as integers. It also functions as a unary plus operator to explicitly denote a positive integer, and it can be combined with the assignment operator (`+=`) to increment a variable.

```bash theme={"dark"}

# Binary addition
result=$(( 5 + 3 ))


# Unary plus
result=$(( +5 ))


# Arithmetic evaluation via 'let' builtin
let "result = 5 + 3"


# Arithmetic compound assignment
(( variable += 5 ))
```

## Parameter Expansion (Alternate Value)

In parameter expansion, `+` is used to test whether a variable is set, substituting an alternate string if the condition is met. It does not modify the original variable.

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

```bash theme={"dark"}

# Evaluates to 'alternate_string' if var is set
echo "${var+alternate_string}"


# Evaluates to 'alternate_string' if var is set AND not empty
result="${var:+alternate_string}"
```

## Extended Globbing (extglob)

When the `extglob` shell option is enabled, `+` acts as a pattern quantifier. It matches one or more occurrences of the specified pattern list. The pattern list can contain multiple patterns separated by the pipe (`|`) character.

```bash theme={"dark"}

# Requires enabling extended globbing
shopt -s extglob


# Matches one or more occurrences of pattern1 or pattern2
ls +(pattern1|pattern2)
```

## Shell Option and Attribute Toggling

When used with the `set` builtin, the `+` operator **disables** shell options, adhering to the POSIX standard specification for shell execution environments. This is the inverse of the `-` operator, which enables them. This identical syntax applies to variable declaration builtins (`declare`, `local`, `typeset`) to remove specific attributes from a variable.

```bash theme={"dark"}

# Disables a shell option via short flag (e.g., xtrace)
set +x


# Disables a shell option via long name (e.g., errexit)
set +o errexit


# Removes the export attribute from a variable
declare +x var_name


# Removes the integer attribute from a local variable
local +i var_name
```

## Regular Expression Quantifier

Within the `[[ ]]` conditional construct utilizing the `=~` binary operator, the right-hand side is evaluated as a POSIX Extended Regular Expression (ERE). In this context, `+` functions as the standard regex quantifier matching one or more occurrences of the preceding element.

```bash theme={"dark"}

# Matches one or more digits
[[ $string =~ [0-9]+ ]]
```

## Compound Assignment (`+=`)

The behavior of the `+=` operator outside of explicit arithmetic contexts is strictly determined by the target variable's attributes and type:

* **Integer Variables:** If the variable has the integer attribute set (e.g., via `declare -i`), the `+=` operator evaluates the right-hand side as an arithmetic expression and performs arithmetic addition.
* **String Variables:** If the integer attribute is not set, the `+=` operator performs literal string concatenation.
* **Arrays:** When applied to arrays using compound assignment syntax, `+=` appends elements. Indexed arrays append values sequentially, whereas associative arrays require explicit key-value subscripts.

```bash theme={"dark"}

# Arithmetic addition (integer attribute set)
declare -i int_var=5
int_var+=5  # Evaluates to 10


# String concatenation (default attribute)
string_var="text"
string_var+=" appended" # Evaluates to "text appended"


# Appends elements to an existing indexed array
indexed_array+=(element1 element2)


# Appends elements to an existing associative array
associative_array+=([key1]=element1 [key2]=element2)
```

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