> ## 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 Right Shift

The `>>` operator is a Bash redirection operator that appends the output of a command to a file. When invoked, the shell opens the target file in append mode (utilizing the `O_APPEND` flag at the system call level). If the target file exists, the file offset is positioned at the end of the file prior to writing, preserving all existing data. If the file does not exist, the shell creates it.

## Syntax

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

* **`n`**: An optional integer representing the file descriptor (FD) to redirect. If omitted, Bash defaults to `1` (standard output / `stdout`).
* **`word`**: The target destination. The shell subjects this to brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, word splitting, pathname expansion (globbing), and quote removal to determine the final filename.

**Ambiguous Redirects:** If the expansions applied to `word` result in more than one word (for example, redirecting to an unquoted variable containing spaces, or a glob pattern that matches multiple files), Bash will fail the command and throw an "ambiguous redirect" error.

## File Descriptor Targeting

Because `>>` operates on file descriptors, it can be prefixed with specific FD integers to control exactly which output stream is appended to the target file.

```bash theme={"dark"}

# Appends standard output (FD 1) implicitly
command >> filename


# Appends standard output (FD 1) explicitly
command 1>> filename


# Appends standard error (FD 2) explicitly
command 2>> filename
```

## Multi-Stream Appending

To append multiple file descriptors to the same file, Bash provides specific syntactic constructs.

**Bash 4.0+ Syntax:**
The `&>>` operator is a dedicated redirection operator that appends both standard output (FD 1) and standard error (FD 2) simultaneously.

```bash theme={"dark"}
command &>> filename
```

**POSIX-Compliant Syntax:**
To achieve the same result in older Bash versions or strictly POSIX-compliant scripts, standard error must be redirected to standard output, and standard output must be appended to the file. The order of evaluation is strictly left-to-right.

```bash theme={"dark"}
command >> filename 2>&1
```

## Execution Mechanics

1. **Parsing:** The shell parses the command line and identifies the `>>` redirection operator.
2. **File Operations:** Before the command is executed, the shell evaluates `word` to resolve the filename. It then issues an `open()` system call on that file with the `O_WRONLY | O_CREAT | O_APPEND` flags.
3. **Duplication:** The shell uses `dup2()` to duplicate the opened file descriptor onto the targeted file descriptor (e.g., FD 1).
4. **Execution:** The command executes, completely unaware of the redirection, writing its output to the file descriptor which now points to the end of the target file.

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