Explaining ‘<<-EOT’ found in Terraform Logs
or on giving instructions for passing a text of multiple lines into a command in Bash via heredoc.
1 min readNov 16, 2022
When writing shell scripts you may be in a situation where you need to pass a multiline block of text or code to an interactive command, such as tee , cat, or sftp .
- It started when I encountered this syntax in Terraform logs → Terraform is using this shell technique
Terraform also supports a “heredoc” style of string literal inspired by Unix shell languages
~ jobspec = <<-EOT
job "com_acme:prod1:{
datacenters = ["eu-central-1a", "eu-central-1b", "eu-central-1c"]
affinity {
attribute = "${meta.rack}"
value = "clients"
weight = 100
}
type = "batch"
periodic {
cron = "36 * * * *"
prohibit_overlap = true
}
config {
- image = "0.98.0"
+ image = "0.99.0"
}
EOT
- It also explains it properly — the heredoc consists of:
- An opening sequence (
<<-EOT
) - A multiline block of test
- The delimiter word was chosen in the opening sequence (
EOT
)
EOT
(end of text) is a typical delimiter, but that is a pure convention
conventionally this identifier is in all-uppercase and begins with EO, meaning “end of”