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

A negated pipeline in Bash is a pipeline prefixed with the `!` reserved word, which logically inverts the final exit status (`$?`) of the executed command sequence. If the underlying pipeline evaluates to a zero exit status (success), the negation forces an exit status of `1`. Conversely, if the pipeline evaluates to a non-zero exit status (failure), the negation forces an exit status of `0`.

## Syntax

```bash theme={"dark"}
! command [ | command2 ... ]
```

## Technical Mechanics

* **Reserved Word Parsing:** The `!` character is parsed as a shell reserved word, not a built-in or external command. It must appear at the beginning of the pipeline and must be separated from the subsequent command by whitespace. Without the trailing space, the interactive shell parser will interpret it as a history expansion directive (e.g., `!command`). Control operators immediately following `!` will either cause a syntax error (e.g., `!|cmd`) or terminate the pipeline entirely (e.g., `!;cmd`). Additionally, while `(` is a control operator, `!(` is tokenized as an extended glob pattern in Bash, meaning a space is strictly required to negate a subshell (e.g., `! (cmd)`).
* **Exit Status Mapping:**
  * Original pipeline exit status `0` -> Negated pipeline exit status `1`.
  * Original pipeline exit status `N` (where `N > 0`) -> Negated pipeline exit status `0`.
* **Multi-Command Pipeline Evaluation:** In a pipeline containing multiple commands (`! cmd1 | cmd2`), the negation applies to the final evaluated exit status of the entire pipeline. By default, this is the exit status of the last command (`cmd2`). If the `pipefail` shell option is enabled, the pipeline's pre-negation status is the exit status of the rightmost command to exit with a non-zero status, or `0` if all commands in the pipeline exit successfully. The `!` reserved word then inverts that final resolved integer.
* **Interaction with `errexit`:** Bash explicitly exempts any pipeline prefixed with `!` from `errexit` (`set -e`) termination. This exemption is a syntactic rule of the shell's error handling, independent of the final inverted exit status. For example, the pipeline `! true` evaluates to an exit status of `1` (a failure), but it will not cause the script to terminate under `set -e` because the `!` reserved word explicitly suppresses the `errexit` evaluation for that pipeline.
* **Subshell Execution Context:** While each command within a standard multi-command pipeline executes in its own subshell by default (unless the `lastpipe` option is enabled), the `!` reserved word itself does not alter this behavior or introduce an additional subshell environment. The negation operation occurs in the parent shell environment after the pipeline's execution completes, simply inverting the returned integer.

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