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-string, is a form of input redirection in Bash that supplies a string directly to the standard input (stdin) of a command. It is a specialized variant of the here-document (<<) designed to feed a single evaluated word into file descriptor 0 without the overhead of invoking a subshell or the echo/printf utilities via a pipe (|).
command [arguments] <<< word

Parsing and Expansion Mechanics

When the Bash parser encounters the <<< operator, it isolates the subsequent word token. Before redirecting the string to the command’s stdin, Bash subjects the word to a specific sequence of shell expansions:
  1. Tilde Expansion: (~ resolves to $HOME)
  2. Parameter and Variable Expansion: ($VAR or ${VAR} are resolved)
  3. Command Substitution: ($(cmd) or `cmd` are executed and replaced by their standard output)
  4. Arithmetic Expansion: ($((expression)) is evaluated)
  5. Quote Removal: (Unescaped single and double quotes are stripped)
Crucial Exception: Bash explicitly bypasses brace expansion, word splitting, and pathname expansion (globbing) for the word token following a here-string operator.

# Variable expansion occurs
command <<< "$MY_VAR"


# Command substitution occurs
command <<< "$(generate_output)"


# No brace expansion occurs; '{a,b}' is treated as literal characters
command <<< {a,b}


# No word splitting or globbing occurs; '*' remains a literal asterisk
command <<< * 
Empty Variable Behavior: Because token recognition occurs before variable expansion, and word splitting is bypassed for here-strings, an unquoted variable that expands to an empty string does not result in a missing token. The parser accepts the variable as a valid token, evaluates it to an empty string, and safely passes a single newline to the command. A syntax error only occurs if the token is literally omitted from the command line prior to parsing.

# Safe execution: evaluates to an empty string, passes a single newline (\n)
command <<< $EMPTY_VAR


# Safe execution: identical behavior, passes a single newline (\n)
command <<< "$EMPTY_VAR"


# Syntax error: bash: syntax error near unexpected token 'newline'

# (The token is literally missing before parsing)
command <<< 

Multiline Strings and Tokenization

Because the here-string operator expects a single word token, unquoted whitespace alters how the shell parses the command line. While the operator accepts only a single token, that token can easily span multiple lines.

# "string" is the here-string. "argument" is passed as an argument to the command.
command <<< string argument


# The entire quoted block is treated as the single here-string token.
command <<< "string argument"


# Multiline strings are fully supported via quoting or ANSI-C quoting.
command <<< "$MULTILINE_VAR"
command <<< $'line1\nline2'

The Trailing Newline

By design, Bash automatically appends a single newline character (\n) to the evaluated string before passing it to the command. If the evaluated word is "data", the command receives "data\n" on its stdin. This behavior is hardcoded into the here-string implementation and cannot be suppressed; if a strict stream of bytes without a trailing newline is required, <<< is the incorrect operator.

Underlying Implementation

Historically, Bash implemented here-strings (and here-documents) by writing the expanded string to a temporary file in /tmp and connecting that file to the command’s stdin. In modern Bash (version 5.1 and later), the shell optimizes this process by attempting to use standard anonymous pipes (pipe()) to avoid disk I/O and improve performance. The shell only falls back to creating standard temporary files (via mkstemp()) if the expanded string exceeds the operating system’s pipe buffer size.
Master Bash with Deep Grasping Methodology!Learn More