Skip to main content

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.

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

[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


# 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.
Master Bash with Deep Grasping Methodology!Learn More