> ## 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 Greater Than

The `>` operator is an output redirection operator in Bash that instructs the shell to route a stream from a specific file descriptor to a target file or device. By default, it redirects standard output (stdout, file descriptor 1). When invoked, the shell performs an `open()` system call on the target file with the `O_WRONLY | O_CREAT | O_TRUNC` flags. This means the file is created if it does not exist, and its size is truncated to zero bytes before any new data is written.

## Syntax

```bash theme={"dark"}
[n]> word
```

* **`[n]`**: An optional integer representing the file descriptor to redirect. If omitted, Bash defaults to `1` (stdout).
* **`>`**: The redirection operator.
* **`word`**: The target destination. The shell subjects this string to brace expansion, tilde expansion, parameter expansion, command substitution, arithmetic expansion, word splitting, pathname expansion (globbing), and quote removal to determine the final file path before the redirection is executed. If the result of these expansions yields more than one word, Bash will fail the redirection with an "ambiguous redirect" error.

## File Descriptor Variations

The operator can be modified by prefixing it with specific file descriptors or by using Bash-specific combined redirection syntax:

```bash theme={"dark"}
1> word    # Explicitly redirects stdout (identical to > word)
2> word    # Redirects standard error (stderr, file descriptor 2)
&> word    # Bash extension: Redirects both stdout and stderr to the file 'word'
>& word    # Redirects both stdout and stderr, with conditional file descriptor duplication
```

While `&>` and `>&` often appear similar, their parsing rules differ significantly. The `&>` operator always treats `word` as a filename (e.g., `&>2` creates a file literally named `2`). In contrast, if the `word` following `>&` evaluates to a number or a hyphen (`-`), `>&` acts as a file descriptor duplication or closing operator (e.g., `>&2` duplicates stdout to stderr). It only falls back to redirecting both streams to a file if `word` does not evaluate to a number or hyphen.

## The `noclobber` Option and `>|`

Because the default behavior of `>` truncates existing files, Bash provides the `noclobber` shell option (`set -C` or `set -o noclobber`) to prevent accidental data loss.

When `noclobber` is enabled, Bash will refuse to redirect output to an existing regular file and will return an error. To forcefully override the `noclobber` restriction and truncate the file regardless of the shell option, the `>|` operator is used:

```bash theme={"dark"}
>| word    # Bypasses noclobber and forces truncation of the file
```

## Execution Order and Evaluation

Redirections are processed by the shell from left to right *before* the command itself is executed. If the shell fails to open the target file specified by the `>` operator (e.g., due to insufficient permissions, a read-only filesystem, or an invalid path), the redirection fails, an error is printed to stderr, and the associated command is aborted before execution.

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