> ## 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 Integer Not Equal

The `-ne` (not equal) operator is a binary arithmetic comparison operator in Bash used to evaluate whether two integer operands have different numeric values. It returns an exit status of `0` (true) if the integers are strictly not equal, and `1` (false) if they are mathematically equal.

## Syntax

The operator requires whitespace on both sides and must be executed within a test construct or the `test` builtin:

```bash theme={"dark"}
[ INT1 -ne INT2 ]
[[ INT1 -ne INT2 ]]
test INT1 -ne INT2
```

## Technical Characteristics

* **Evaluation Context and Type Constraints:** The `-ne` operator forces an arithmetic evaluation context, but its handling of non-numeric strings depends entirely on the enclosing construct:
  * **Inside `[ ]` and `test`:** Both operands must strictly resolve to integers. If an operand is a non-numeric string or empty, Bash throws an `integer expression expected` runtime evaluation error. The command outputs the error message to standard error and returns an exit status of `2`. If the `errexit` option (`set -e`) is enabled, this non-zero exit status will immediately terminate the script unless the test is evaluated as part of a control structure.
  * **Inside `[[ ]]`:** The operator evaluates its operands as *arithmetic expressions* (equivalent to the evaluation performed inside `$(( ))`). Strings containing mathematical operations (e.g., `"1 + 1"`) are computed prior to comparison. If an operand is an unexpanded string that forms a valid identifier (e.g., `[[ var -ne 0 ]]`), Bash evaluates the variable's contents. If the variable is unset or explicitly initialized with an empty string (`var=""`), it evaluates to `0` in this arithmetic context (though an unset variable will trigger an `unbound variable` error if `set -u` is enabled). Conversely, if the variable is explicitly expanded and results in an empty string (e.g., `[[ "$var" -ne 0 ]]`), Bash encounters a missing operand and throws an arithmetic syntax error (`operand expected`).
* **Base Handling:** When used inside the extended test construct `[[ ]]`, operands with leading zeros may be evaluated as octal, and arithmetic expressions are evaluated directly. Inside POSIX single brackets `[ ]`, operands are treated strictly as base-10 integers.
* **Exit Status Mapping:**
  * `INT1 != INT2` → Exit code `0` (True)
  * `INT1 == INT2` → Exit code `1` (False)

## `-ne` vs. `!=`

In Bash, the operator itself defines the comparison type. It is critical to distinguish `-ne` from `!=`:

* `-ne` performs **arithmetic** comparison. It evaluates the mathematical value (e.g., `05` and `5` are equal, so `-ne` returns `1`).
* `!=` performs **lexicographical (string)** comparison. It evaluates the exact character sequence (e.g., `"05"` and `"5"` are different strings, so `!=` returns `0`).

```bash theme={"dark"}

# Arithmetic evaluation: 05 and 5 are mathematically equal.

# Exit status: 1 (False)
[ 05 -ne 5 ]


# Lexicographical evaluation: "05" and "5" are different strings.

# Exit status: 0 (True)
[ "05" != "5" ]
```

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