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, known as a Here Document or Heredoc, is an I/O redirection mechanism that instructs the Bash parser to read a block of multi-line text from the current source and feed it to a command’s standard input (stdin). The shell continues reading until it encounters a line containing only a predefined, user-specified delimiter.
command <<DELIMITER
document_body
DELIMITER

Lexical Rules and Parsing Mechanics

  • Delimiter Constraints: The terminating DELIMITER must appear on a line by itself. It cannot be preceded by any characters (including spaces), cannot be followed by any characters (including comments), and must match the opening identifier exactly.
  • Standard Expansion: By default, the shell subjects the document_body to parameter expansion ($VAR), command substitution ($(command)), and arithmetic expansion ($((expression))). The backslash (\) acts as an escape character to prevent specific expansions.
  • Literal Evaluation (Quoted Delimiter): If any character of the opening DELIMITER is quoted (using single quotes 'EOF', double quotes "EOF", or escaping \EOF), the shell disables all expansions. The entire document_body is passed to the command as raw, literal text.

The Tab-Stripping Modifier (<<-)

Appending a hyphen to the operator alters the parsing behavior to ignore leading tab characters.
command <<-DELIMITER
	document_body
	DELIMITER
When <<- is used, Bash strips all leading tab characters (\t)—but not spaces—from every line within the document_body as well as from the line containing the terminating DELIMITER. This mechanism exists strictly to allow the Here Document to be indented naturally within the source code without passing the indentation whitespace to the command’s stdin.
Master Bash with Deep Grasping Methodology!Learn More