Skip to content

Scripting

8 min

Here-documents

A block of text as input, and the one switch that matters.

A here-document feeds a block of text to a command's standard input. The body is expanded like a double-quoted string, so a $ in it is a variable.

Quoting the delimiter turns the whole body literal. That is the switch people reach for the moment a heredoc full of dollars starts producing surprises.

Try this

<<- strips leading tabs from the body so the block can be indented with the code around it. It does not strip spaces, which is the single most common surprise with it.

<<< is a here-string: one line, no delimiter, useful for feeding a single value to something that only reads standard input.

Try this

$

Files

The files in the sandbox, with their modes, link counts and sizes
ModeLinksSizeName
-rw-r--r--169invoice.txt
-rw-r--r--193minutes.md