> ## 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 Logical OR

The `||` (logical OR) operator is a control operator in Bash that executes a subsequent command only if the preceding command terminates with a non-zero exit status (failure). It utilizes short-circuit evaluation to dictate execution flow based on process return codes.

```bash theme={"dark"}
command1 || command2
```

## Execution Mechanics

Bash evaluates the expression strictly from left to right:

1. `command1` is executed.
2. If `command1` returns an exit status of `0` (success), short-circuiting occurs. `command2` is ignored, and the overall exit status of the list is `0`.
3. If `command1` returns a non-zero exit status (failure), `command2` is executed. The overall exit status of the list becomes the exit status of `command2`.

## Chaining Commands

Multiple `||` operators can be chained. Due to left associativity, Bash evaluates the chain sequentially until one command returns `0`.

```bash theme={"dark"}
command1 || command2 || command3
```

If `command1` fails, `command2` executes. If `command2` succeeds, `command3` is skipped. The chain terminates evaluation as soon as a single command yields a `0` exit status.

## Precedence and Grouping

The `||` operator shares equal precedence with the `&&` (logical AND) operator. When mixed in a single list without grouping, they are evaluated strictly left-to-right. To override default precedence, commands must be grouped using braces (executing in the current shell context) or parentheses (executing in a subshell context).

```bash theme={"dark"}

# Default left-to-right evaluation
command1 || command2 && command3


# Grouped evaluation overriding default precedence
command1 || { command2 && command3; }
```

## Interaction with `set -e` (errexit)

When the `set -e` shell option is enabled, Bash normally exits immediately if a pipeline returns a non-zero status. However, if a failing command is part of an `||` list (specifically, any command except the final one in the chain), the `errexit` rule is suppressed. The shell will not exit, allowing the right-hand command to handle the failure state.

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