> ## 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 Negated Character Class

A negated character class in Bash is a pattern matching construct that evaluates to exactly one character *not* present in a specified set or range. It is evaluated by the Bash pattern matching engine during pathname expansion (globbing), `case` statement execution, conditional expression matching (`[[ string == pattern ]]`), and parameter expansion (e.g., `${var#pattern}`, `${var%pattern}`, `${var//[!0-9]/}`).

```bash theme={"dark"}
[!CHARACTERS]
[^CHARACTERS]
```

## Technical Mechanics

* **Negation Operators:** The exclamation mark (`!`) is the POSIX-compliant negation operator for shell pattern matching. Bash also accepts the caret (`^`) to mirror regular expression syntax, but `!` is required for strict POSIX portability.
* **Positional Requirement:** The negation operator (`!` or `^`) must be the immediate first character following the opening bracket `[`. If placed anywhere else within the brackets, it loses its negation property and is parsed as a literal character.
* **Arity:** A negated character class always consumes exactly one character in the target string. It cannot match zero characters, nor can it match multiple characters.

## Syntax Variations

**Discrete Sets**
Matches any single character that is not explicitly listed.

```bash theme={"dark"}
[!abc]    # Matches any character except 'a', 'b', or 'c'
```

**Character Ranges**
Matches any single character whose collation value falls outside the defined start and end boundaries. Bash evaluates character ranges using the current locale's collation sequence (determined by the `LC_COLLATE` environment variable). In many common locales (such as `en_US.UTF-8`), this utilizes dictionary sorting (e.g., `aAbBcC`), meaning a negated range like `[!A-Z]` may unexpectedly exclude lowercase letters. Strict ASCII/Unicode byte-order evaluation is only applied if the locale is explicitly set to `C` or `POSIX`.

```bash theme={"dark"}
[!0-9]    # Matches any character outside the range '0' through '9'
```

**Combined Sets and Ranges**
Multiple ranges and discrete characters can be combined within a single negated class.

```bash theme={"dark"}
[!a-fA-F0-9_] # Matches any character that is not a hex digit or underscore
```

## Parsing Rules for Special Characters

When constructing a negated character class, certain characters require specific positioning to be treated as literals rather than syntax operators:

* **Literal Hyphen (`-`):** To exclude a literal hyphen without creating an invalid range, the hyphen must be placed immediately after the negation operator or at the very end of the class.

```bash theme={"dark"}
[!-abc]   # Excludes '-', 'a', 'b', and 'c'
[!abc-]   # Identical parsing to the above
```

* **Literal Closing Bracket (`]`):** To exclude a literal closing bracket, it must be placed immediately after the negation operator. Bash parses the first `]` it encounters as the end of the class unless it is in this specific position.

```bash theme={"dark"}
[!]]      # Excludes the literal character ']'
```

* **Literal Exclamation/Caret (`!` / `^`):** If these characters appear anywhere other than the first position, the parser treats them as standard literal characters to be included in the set.

```bash theme={"dark"}
[a!b]     # NOT NEGATED. Matches exactly 'a', '!', or 'b'
[!a!b]    # NEGATED. Excludes 'a', '!', and 'b'
```

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