Heredoc

2 snippets across 2 stacks — Bash & Linux, Python

SHBash & Linux

Here Document

SH · Redirects & Pipes
syntax
command <<DELIMITER
text
DELIMITER
example
cat <<EOF > /etc/nginx/conf.d/app.conf
server {
    listen 80;
    server_name app.example.com;
    location / {
        proxy_pass http://localhost:3000;
    }
}
EOF

# Suppress variable expansion:
cat <<'EOF'
Use $HOME to reference your home directory
EOF

Note Variables and commands are expanded inside a here document by default. Quoting the delimiter ('EOF') disables expansion, which is useful when writing scripts or config files that contain $ characters. <<- strips leading tabs (not spaces) for cleaner indentation.

PYPython

Multiline Strings

PY · Strings
syntax
"""text
spanning lines"""
example
query = """
    SELECT name, email
    FROM users
    WHERE active = true
""".strip()
print(query)
output
SELECT name, email
    FROM users
    WHERE active = true

Note Triple-quoted strings preserve all whitespace and newlines. Use textwrap.dedent() or .strip() to control leading/trailing space.