> ## 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 Right Shift Assignment

The `>>=` operator in Bash is the **bitwise right shift assignment operator**. It operates exclusively within arithmetic evaluation contexts to shift the binary representation of a variable's integer value to the right by a specified number of bits, immediately assigning the resulting value back to the original variable.

```bash theme={"dark"}
(( variable >>= shift_amount ))

# or
let "variable >>= shift_amount"
```

## Operational Mechanics

* **Expression Equivalence:** The operation `(( x >>= y ))` is the shorthand assignment equivalent of `(( x = x >> y ))`.
* **Context Requirement:** The operator requires an explicit arithmetic execution environment, invoked via `(( ... ))`, `$(( ... ))`, or `let`. Unlike standard assignment operators (`=` or `+=`), `>>=` is not recognized as a valid token in standard shell command contexts, even if the target variable is strictly typed with `declare -i`.
* **Recursive Integer Evaluation:** Bash dynamically evaluates variables as signed integers (typically a 64-bit `intmax_t` on modern architectures). If the variable contains a non-numeric string, Bash evaluates that string recursively as an arithmetic expression or a variable reference. A string evaluates to `0` if it ultimately resolves to an uninitialized variable, an initialized variable currently holding the value `0`, or an arithmetic expression that mathematically equals zero (e.g., `"10 - 10"`).
* **Sign Bit Propagation (Arithmetic Shift):** Because Bash utilizes signed integers, `>>=` performs an *arithmetic* right shift rather than a logical right shift. The most significant bit (the sign bit) is preserved and propagated to fill the vacated bit positions on the left.
  * For positive integers (sign bit `0`), vacated bits are filled with `0`s.
  * For negative integers (sign bit `1`, represented in two's complement), vacated bits are filled with `1`s.
* **Mathematical Property:** A bitwise right shift by *n* bits is mathematically equivalent to integer floor division by 2<sup>n</sup>.

## Evaluation Examples

```bash theme={"dark"}

# Positive integer shift
val=24          # Binary: ...00011000
(( val >>= 2 )) # Shifts right by 2 bits
echo $val       # Output: 6 (Binary: ...00000110)


# Negative integer shift (Two's complement sign propagation)
val=-16         # Binary: ...11110000
(( val >>= 2 )) # Shifts right by 2 bits
echo $val       # Output: -4 (Binary: ...11111100)


# Recursive evaluation of string variables
foo=32
str_val="foo"
(( str_val >>= 3 )) # "foo" recursively resolves to the variable foo (32). 32 >> 3 is 4.
echo $str_val       # Output: 4


# Evaluation of strings resolving to zero
str_val2="10 - 10"
(( str_val2 >>= 1 )) # "10 - 10" mathematically resolves to 0. 0 >> 1 is 0.
echo $str_val2       # Output: 0
```

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