Shell Scripts and Here Documents

Written By
JK
Juliet Kemp
Jan 26, 2010

“A here document (or heredoc) is a way of getting text input
into a script without having to feed it in from a separate file. If
you’ve got a small quantity of data you don’t expect to change
often, it’s a quick and tidy way of keeping script and data
together. For more complicated data or scripts, separating the two
is still usually a better idea.

“The basic version of this in bash looks like this:

#!/bin/bash
cat << EOF
several lines of 
my data
listed here
EOF

“which will output

several lines of 
my data
listed here

Complete
Story

JK

Juliet Kemp

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.