> ## 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.

# Bash Here String

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 (`|`).

```bash theme={"dark"}
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.

```bash theme={"dark"}

# 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.

```bash theme={"dark"}

# 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.

```bash theme={"dark"}

# "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.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Bash Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
