> ## 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 String Is Empty

The `-z` operator is a unary string evaluation operator in Bash that returns true (exit status `0`) if the length of its string operand is exactly zero, and false (exit status `1`) otherwise. It is executed within the `test` built-in command or conditional expression constructs (`[ ]` and `[[ ]]`) to evaluate the initialization or population state of a variable.

## Syntax

```bash theme={"dark"}

# POSIX-compliant test command
test -z "$STRING"


# POSIX-compliant single bracket syntax
[ -z "$STRING" ]


# Bash-specific double bracket keyword syntax
[[ -z $STRING ]]
```

## Evaluation Mechanics

* **Unset Variables:** By default, if the operand is an uninitialized (unset) variable, Bash expands it to an empty string prior to evaluation. The `-z` operator processes this as a zero-length string and evaluates to true (`0`). However, if the `nounset` shell option is active (`set -u` or `set -o nounset`), referencing an unset variable (e.g., `[ -z "$VAR" ]`) triggers an "unbound variable" error and halts execution. To safely evaluate a potentially unset variable under `set -u`, use default parameter expansion (e.g., `[ -z "${VAR:-}" ]`) to provide an empty fallback without triggering the error.
* **Whitespace:** A string containing only whitespace characters (e.g., `"   "`) has a length greater than zero. The `-z` operator evaluates this as false (`1`).
* **Complement Operator:** The logical inverse of `-z` is `-n`, which evaluates to true if the string length is non-zero.

## Quoting and Parsing Rules

The parsing behavior of `-z` depends heavily on the conditional construct used and the application of double quotes around the operand:

* **Single Brackets (`[ ]`):** The operand undergoes word splitting and pathname expansion. If the variable is unquoted and empty, the expression expands to `[ -z ]`. The `test` built-in interprets this as a single-argument test evaluating the literal string `"-z"`, which evaluates to true (exit status `0`) because the string `"-z"` has a non-zero length. If the unquoted variable contains spaces, it splits into multiple arguments (e.g., `VAR="a b"` expanding to `[ -z a b ]`), which results in a `too many arguments` error. **Double quoting (`"$VAR"`) is strictly required.**
* **Double Brackets (`[[ ]]`):** This construct is a shell keyword that suppresses word splitting and pathname expansion. The expression `[[ -z $VAR ]]` is parsed safely even if `$VAR` is empty or contains spaces. While quoting is not strictly required here, it is universally recommended for consistency.

## Exit Status Codes

| Condition                                           | Exit Status | Result                                                                |
| :-------------------------------------------------- | :---------- | :-------------------------------------------------------------------- |
| `length(STRING) == 0`                               | `0`         | True                                                                  |
| `length(STRING) > 0`                                | `1`         | False                                                                 |
| Missing operand in `[ ]` or `test` (e.g., `[ -z ]`) | `0`         | True (POSIX single-argument rule evaluates literal `"-z"`)            |
| Missing operand in `[[ ]]` (e.g., `[[ -z ]]`)       | `0`         | True (Bash treats `-z` as a literal string if no operand is provided) |

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