> ## 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 Bitwise OR Assignment

The `|=` operator in Bash is the bitwise inclusive OR assignment operator. It performs a bitwise OR operation between a variable (the left-hand side operand) and an evaluated expression (the right-hand side operand), and immediately assigns the resulting integer back to the variable.

## Syntax

Because Bash variables are untyped strings by default, the `|=` operator must be executed within an arithmetic evaluation context.

```bash theme={"dark"}
(( variable |= expression ))
```

Alternatively, it can be used with the `let` builtin:

```bash theme={"dark"}
let "variable |= expression"
```

## Mechanics

1. **Operand Evaluation:** The right-hand side expression is fully evaluated as an integer.
2. **Bitwise OR (`|`):** Bash converts both the current value of the variable and the evaluated right-hand side into their underlying binary representations (typically 64-bit signed integers, depending on the system architecture). It then compares them bit by bit. If a bit is `1` in *either* operand, the corresponding bit in the result is set to `1`. It is set to `0` only if both bits are `0`.
3. **Assignment (`=`):** The final binary result is converted back to a base-10 integer and assigned to the left-hand side variable.

## Equivalence

The compound assignment `|=` is strictly syntactic sugar for a standard bitwise OR operation followed by an assignment:

```bash theme={"dark"}
(( x |= y ))


# is functionally identical to:
(( x = x | y ))
```

## Evaluation Example

When the operator is applied, the operation occurs at the binary level:

```bash theme={"dark"}
x=10         # Binary representation: 1010
(( x |= 6 )) # Binary representation: 0110
             # Bitwise OR result:     1110 (Decimal 14)

echo $x      # Outputs: 14
```

## Operator Precedence

In Bash arithmetic, the `|=` operator shares the second-lowest precedence level with other assignment operators (such as `=`, `+=`, `&=`, etc.), sitting strictly above the comma operator (`,`), which has the lowest precedence. Assignment operators evaluate right-to-left. Consequently, the entire right-hand side expression is evaluated before the bitwise OR assignment takes place.

```bash theme={"dark"}
x=2
(( x |= 1 << 2 )) # The bitwise shift (1 << 2) evaluates to 4 first.
                  # Then, x |= 4 is executed.
                  # x becomes 6.
```

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