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

The `%` operator in Bash serves three distinct syntactic roles depending on its evaluation context: an arithmetic modulo operator, a parameter expansion operator for suffix removal, and a job control specifier.

## Arithmetic Modulo Operator

Within an arithmetic evaluation context, `%` functions as the modulo operator. It evaluates the remainder of integer division between two operands. Because Bash natively supports only integer arithmetic, floating-point operands will result in a syntax error.

**Syntax:**

```bash theme={"dark"}
$(( dividend % divisor ))
(( dividend % divisor ))
let "var = dividend % divisor"
```

**Mechanics:**

* Evaluated exclusively inside Bash's internal arithmetic contexts (`$(( ))`, `(( ))`, or `let`).
* The sign of the result matches the sign of the dividend.
* Division by zero throws a `division by 0` runtime error.

**Example:**

```bash theme={"dark"}
echo $(( 10 % 3 ))   # Outputs: 1
echo $(( -10 % 3 ))  # Outputs: -1
```

## Parameter Expansion (Suffix Pattern Removal)

Within parameter expansion, `%` acts as a pattern-matching operator that strips a specified suffix from a variable's string value. It uses standard shell globbing rules (not regular expressions) to match the pattern against the end of the string.

**Syntax:**

```bash theme={"dark"}
${variable%pattern}   # Non-greedy (shortest match)
${variable%%pattern}  # Greedy (longest match)
```

**Mechanics:**

* **Single `%` (Non-greedy):** Deletes the shortest possible match of the `pattern` from the right side (suffix) of the expanded `$variable`.
* **Double `%%` (Greedy):** Deletes the longest possible match of the `pattern` from the right side of the expanded `$variable`.
* If the pattern does not match the suffix, the original string is returned unmodified.

**Example:**

```bash theme={"dark"}
string="base.module.ext"

echo ${string%.*}   # Outputs: base.module (strips shortest match of ".*")
echo ${string%%.*}  # Outputs: base (strips longest match of ".*")
```

## Job Control Specifier

In an interactive shell environment (or scripts where `set -m` is enabled), `%` is used as a prefix to reference background or suspended jobs by their job ID or command string, rather than their Process ID (PID).

**Syntax:**

```bash theme={"dark"}
%        # References the current job (synonym for %% and %+)
%%       # References the current (most recently foregrounded/backgrounded) job
%+       # Same as %%
%-       # References the previous job
%n       # References job number 'n'
%string  # References the job whose command begins with 'string'
%?string # References the job whose command contains 'string'
```

**Example:**

```bash theme={"dark"}
fg %1       # Brings job 1 to the foreground
kill -15 %  # Sends SIGTERM to the current job
```

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