TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
< 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).
< implicitly targets standard input, the standard syntax is functionally identical to explicitly declaring file descriptor 0:
Execution Mechanics
When the shell encounters the< operator, it performs the following sequence of operations before the target command is executed:
- Parsing: The shell identifies the redirection operator and isolates the target
filename. - System Calls: The shell attempts to open
filenameusing theopen()system call with theO_RDONLY(read-only) flag. - File Descriptor Duplication: If the file opens successfully, the shell uses the
dup2()system call to duplicate the newly acquired file descriptor onto file descriptor0. - Command Invocation: The shell executes the command. The command remains entirely agnostic to the redirection; it simply reads from
stdinvia 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’sopen() 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:
Master Bash with Deep Grasping Methodology!Learn More





