> ## 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 String Equal

The `==` operator in Bash is a binary comparison operator whose behavior—evaluating literal string equality, pattern matching, or numeric equivalence—is strictly dictated by the evaluation context (`[[ ]]`, `[ ]`, or `(( ))`) enclosing it.

## Execution Contexts

### 1. Extended Test Keyword (`[[ ]]`)

Within the Bash-specific `[[ ]]` construct, the `==` operator performs **pattern matching** (globbing) and **string equality**. The exact behavior depends on the quoting of the right-hand operand and shell options.

```bash theme={"dark"}

# Syntax: Pattern Matching / Partial Quoting
[[ "$left_operand" == "$prefix"* ]]


# Syntax: Literal String Equality
[[ "$left_operand" == "$exact_match" ]]
```

* **Quoting and Partial Quoting:** The right-hand operand is evaluated dynamically based on quotes. Characters enclosed in single (`'`) or double (`"`) quotes are forced to match as literal strings. Unquoted characters are evaluated as glob patterns (`*`, `?`, `[...]`). This allows for partial quoting, where variables or literal strings can be safely concatenated with unquoted wildcards.
* **Case Sensitivity (`nocasematch`):** By default, the `==` operator performs case-sensitive matching. Enabling the `nocasematch` shell option (`shopt -s nocasematch`) alters the operator's behavior within `[[ ]]` to evaluate both literal strings and patterns case-insensitively.

### 2. Arithmetic Evaluation (`(( ))`, `$(( ))`, `let`)

Within arithmetic contexts, the `==` operator performs **numeric equivalence**. It evaluates the mathematical value of the operands rather than their character sequence.

```bash theme={"dark"}

# Syntax: Numeric Equivalence
(( left_operand == right_operand ))
```

* **Numeric Parsing:** Because it evaluates mathematical integers, differing string representations of the same number (e.g., leading zeros, evaluated variables, or different bases) evaluate as equal. For example, `(( "01" == "1" ))` evaluates to true, whereas the same operands in a string context (`[[ "01" == "1" ]]`) evaluate to false.

### 3. POSIX Test Command (`[ ]` or `test`)

Within the standard `[ ]` construct, the `==` operator strictly performs **literal string equality**. Pattern matching is not supported in this context.

```bash theme={"dark"}

# Syntax: Literal String Equality
[ "$left_operand" == "$right_operand" ]
```

*Note: While Bash parses `==` in `[ ]` as a valid synonym for string equality, the single `=` operator is the strict POSIX standard for the `test` command. The `==` operator is a Bash extension.*

## Evaluation Mechanics

* **Whitespace Sensitivity:** In test constructs (`[ ]` and `[[ ]]`), operands must be separated from the `==` operator by whitespace. Omitting whitespace (e.g., `[[ "$a"=="$b" ]]`) causes Bash to parse the entire expression as a single, non-empty string. Because Bash evaluates any non-empty string as true, this results in a silent false-positive test.
* **Exit Status:** In compound commands (`[[ ]]`, `[ ]`, `(( ))`), the operator yields an exit status of `0` (true) if the condition is met, and `1` (false) if it is not.
* **Expansion Output:** When used within arithmetic expansion (`$(( ))`), the operator does not yield an exit status directly; instead, it expands to the string `"1"` for true and `"0"` for false.

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