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 its contents to the standard input (stdin, file descriptor 0) of a command, replacing the default input stream (typically the terminal keyboard).
Syntax
n: An optional integer representing the file descriptor to be modified. If omitted, Bash defaults to0(standard input).word: The target file to be opened. Before redirection occurs,wordis subject to brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, word splitting, pathname expansion (globbing), and quote removal.
Underlying Mechanics
-
Parsing and Evaluation: Redirection is processed by the shell before the associated command is executed. The shell parses the command line, identifies the
<operator, and evaluateswordto resolve the target filepath. -
System Calls: The shell invokes the
open()system call on the resolvedwordwith theO_RDONLY(read-only) flag. -
File Descriptor Duplication: If the file opens successfully, the shell uses the
dup2()system call to duplicate the newly obtained file descriptor onto file descriptor0(or the explicitly providedn). -
Command Execution: The method of execution depends on the command type:
- External Commands: The shell forks a child process, applies the file descriptor modifications, and invokes an
execsystem call to run the command. - Shell Builtins and Functions: The shell temporarily duplicates and saves the original file descriptors, applies the redirection within the current process, executes the builtin or function, and then restores the original file descriptors without invoking
exec.
- External Commands: The shell forks a child process, applies the file descriptor modifications, and invokes an
Failure States
If the redirection fails prior to command execution, the shell aborts the command and returns a non-zero exit status. Common failure conditions include:- Ambiguous redirect: The expansions applied to
wordresult in more than one word (e.g.,command < *.txtwhen multiple matching files exist). - File not found: The resolved
worddoes not exist (ENOENT). - Permission denied: The executing user lacks read permissions for the file (
EACCES). - Is a directory: The resolved
wordpoints to a directory rather than a file (EISDIR).
Explicit File Descriptor Mapping
While typically used without the optionaln prefix, the operator can be bound to custom file descriptors for advanced stream manipulation.
Master Bash with Deep Grasping Methodology!Learn More





