> ## 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 Read and Write Redirection

The `<>` operator is a bidirectional I/O redirection operator that instructs the shell to open a specified file for both reading and writing, assigning it to a specific file descriptor. Unlike standard output redirection (`>`), it does not truncate an existing file, and the file offset is initialized at the beginning of the file (byte 0). If the target file does not exist, the shell creates it.

## Syntax

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

* **`n`**: An optional integer representing the file descriptor to be allocated. If `n` is omitted, the shell defaults to file descriptor `0` (standard input).
* **`<>`**: The read/write redirection operator.
* **`word`**: The target file path. This undergoes standard shell expansions (tilde, parameter, command, arithmetic, and quote removal) before the redirection is executed.

## Mechanical Behavior

When the shell encounters this operator, it executes an `open()` system call on the target file with the `O_RDWR | O_CREAT` flags.

1. **File Descriptor Binding**: The opened file is bound to the specified file descriptor `n`. Both read and write system calls can subsequently be issued against this single file descriptor.
2. **Pointer Initialization**: The internal read/write pointer is set to the absolute beginning of the file.
3. **Non-Destructive Open**: Because the `O_TRUNC` flag is omitted, pre-existing data within the file is preserved. Any subsequent write operations will overwrite existing bytes sequentially from the current pointer position, rather than clearing the file beforehand.
4. **Creation**: If the file specified by `word` does not exist, it is created using the default permissions, subject to the current shell `umask`.

## Execution Context

```bash theme={"dark"}

# Opens 'file.txt' for reading and writing on file descriptor 3
exec 3<> file.txt


# Opens 'file.txt' for reading and writing on file descriptor 0 (stdin)
exec <> file.txt
```

When used with the `exec` builtin, the redirection modifies the file descriptors of the current shell environment. When appended to a standard command, the redirection is scoped exclusively to the execution environment of that specific command, closing the file descriptor immediately after the command terminates.

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