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 the standard input redirection operator in Bash. It instructs the shell to open a specified file for reading and map it to the standard input (stdin, file descriptor 0) of a command, replacing the default input stream (typically the terminal).
command < filename
Because < implicitly targets standard input, the standard syntax is functionally identical to explicitly declaring file descriptor 0:
command 0< filename

Execution Mechanics

When the shell encounters the < operator, it performs the following sequence of operations before the target command is executed:
  1. Parsing: The shell identifies the redirection operator and isolates the target filename.
  2. System Calls: The shell attempts to open filename using the open() system call with the O_RDONLY (read-only) flag.
  3. File Descriptor Duplication: If the file opens successfully, the shell uses the dup2() system call to duplicate the newly acquired file descriptor onto file descriptor 0.
  4. Command Invocation: The shell executes the command. The command remains entirely agnostic to the redirection; it simply reads from stdin via standard POSIX read operations, unaware that the stream originates from a file rather than a TTY device.

Error Handling and Preemption

Because redirection is handled by the shell prior to command execution, any failure in the redirection phase preempts the command. If the target file does not exist, is a directory, or lacks the necessary read permissions, the shell’s open() call fails. The shell will immediately output an error to standard error (stderr), return a non-zero exit status, and abort the execution. The target command is never spawned.

Positional Independence

The Bash parser evaluates redirection independently of command arguments. The < operator and its target file can be placed anywhere in the command string. The shell strips the redirection instruction from the argument list before passing the remaining arguments to the execve() system call. The following syntaxes are parsed identically by the shell:

# Standard trailing placement
command arg1 arg2 < filename


# Leading placement
< filename command arg1 arg2


# Interleaved placement
command arg1 < filename arg2
Master Bash with Deep Grasping Methodology!Learn More