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

The `<<` operator, known as a **Here-Document** (or heredoc), is an I/O redirection mechanism in Bash. It instructs the shell to read a block of string literals from the current input stream and redirect it to the standard input (`stdin`) of a specified command. The shell continues reading until it encounters a predefined, user-specified delimiter token on a line by itself.

```bash theme={"dark"}
command << DELIMITER
String content line 1
String content line 2
DELIMITER
```

## Parsing and Expansion Mechanics

By default, the shell parses the body of a Here-Document similarly to a double-quoted string. It subjects the content to three specific types of expansion before passing it to the command:

1. **Parameter Expansion** (`$VAR`)
2. **Command Substitution** (`$(command)` or `` `command` ``)
3. **Arithmetic Expansion** (`$((expression))`)

To prevent the shell from evaluating a specific character (like `$`, `` ` ``, or `\`), it must be escaped using a backslash (`\`).

## Delimiter Quoting (Literal Mode)

If any character of the opening delimiter is quoted (using single quotes, double quotes, or a backslash), the shell alters its parsing behavior. It disables all expansions within the Here-Document body, treating the entire block as a raw, literal string.

```bash theme={"dark"}

# Single quotes
command << 'EOF'
$VAR will not be expanded here.
EOF


# Double quotes
command << "EOF"
$(command) will not execute here.
EOF


# Backslash escape
command << \EOF
$((1 + 1)) remains literal text.
EOF
```

## The `<<-` Variant (Tab Stripping)

Appending a hyphen to the operator (`<<-`) modifies the shell's whitespace handling. When `<<-` is used, the shell strips all leading tab characters (`\t`) from every line within the Here-Document body, as well as from the line containing the closing delimiter.

This variant exists strictly for source code formatting, allowing the Here-Document to be indented to match the surrounding script structure without passing the indentation to the command's `stdin`.

```bash theme={"dark"}
if true; then
	command <<- EOF
		This line has leading tabs stripped.
		So does this one.
	EOF
fi
```

*Note: The `<<-` operator strictly strips tab characters. Leading spaces are preserved and passed to the command.*

## Termination Constraints

The shell enforces strict lexical rules for the closing delimiter:

* It must be the exact character sequence specified by the opening delimiter.
* It must reside on its own line.
* It cannot be preceded by any characters (except tabs if `<<-` is used).
* It cannot be followed by any characters, including trailing spaces, semicolons, or comments.

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