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

The `&&` (logical AND) operator is a control operator used to chain commands based on their exit status. It implements short-circuit evaluation, executing the right-hand command strictly if, and only if, the left-hand command terminates with an exit status of zero (success).

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

## Execution Mechanics

Bash parses the entire command line or script block for syntax before any execution begins. If no syntax errors are found, execution proceeds as follows:

1. Bash executes `command1` and captures its exit status (`$?`).
2. If the exit status is `0` (success), Bash proceeds to execute `command2`.
3. If the exit status is non-zero (`1-255`, indicating failure), Bash short-circuits the evaluation. `command2` is not executed.

## Exit Status Propagation

The overall exit status of an `&&` command list is determined by the last command executed within that list:

* If `command1` fails, the list returns the non-zero exit status of `command1`.
* If `command1` succeeds, the list returns the exit status of `command2`, regardless of whether `command2` succeeds or fails.

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

When the `errexit` option (`set -e`) is enabled, Bash normally exits immediately if a command yields a non-zero exit status. However, according to POSIX and Bash semantics, the `errexit` rule is ignored for any command in an AND-OR list except the last one. Consequently, if `command1` fails, the overall `&&` list returns a non-zero exit status, but this does **not** trigger `set -e` to halt the script. The script will only terminate if the final command in the chain (e.g., `command2`) is executed and fails.

## Associativity and Chaining

The `&&` operator is left-associative and shares equal precedence with the `||` (logical OR) operator. When chaining multiple commands, evaluation proceeds strictly from left to right.

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

In this sequence, `command3` is executed only if both `command1` and `command2` sequentially return an exit status of `0`. A non-zero exit status at any point breaks the chain immediately.

## Contextual Overloading

Beyond operating as a command list control operator, `&&` is overloaded in specific Bash evaluation contexts:

* **Extended Test Construct (`[[ ]]`):** Acts as a logical AND operator between conditional expressions. It evaluates the results of specific conditional test operators (such as string comparisons, `-z`, or `-f`), rather than generic boolean "truthiness".
  ```bash theme={"dark"}
  ```

\[\[ expression1 && expression2 ]]

````
* **Arithmetic Evaluation (`(( ))`):** Acts as a logical AND operator for integer arithmetic. If both expressions evaluate to non-zero integers, the arithmetic expression evaluates to the integer value `1`. This resulting non-zero integer causes the `(( ))` compound command to terminate with an exit status of `0` (success). Conversely, if the arithmetic expression evaluates to the integer `0`, the compound command terminates with an exit status of `1` (failure).
  ```bash
(( integer1 && integer2 ))
````

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