[SOLVED] EOH - what does it mean


#1

Hi,

This will be a simple one but just trying to understand Chef Syntax :

When you have a powershell script : (example taken from https://docs.chef.io/resource_powershell_script.html

powershell_script ‘write-to-interpolated-path’ do
code <<-EOH
$stream = [System.IO.StreamWriter] “#{Chef::Config[:file_cache_path]}/powershell-test.txt”
$stream.WriteLine(“In #{Chef::Config[:file_cache_path]}…word.”)
$stream.close()
EOH
end

and you enclose the required code in EOHs.

What does the acronym EOH actually stand for - End of … but then you need one at the beginning as well so cant be end of …

Not a P1 emergency in any sense I know but helps for me to learn. :slight_smile:

many thanks

David


#2

Those are called HereDocs or Here Documents. They are used in multiple languages as a way to define multi line strings.

http://tldp.org/LDP/abs/html/here-docs.html

The acutal letters you use don’t matter. I suspect EOH stands for end of hunk. You will also commonly see this refered to as EOF

foo <<EOH
line 1
line 2
EOH

bar <<EOF
line 1
line 2
EOF

buzz <<PUPPIES
are 
the
best
PUPPIES

#3

That form of string is called a “here doc”. It’s either “end of here” or “end of hunk”. Either way, the literal that you use to specify the end of the string is arbitrary. EOH or EOF is just convention.


#4

Thank you both spuder & mattlqx for your explanations :smile: Makes sense to me now …

Have a great day

David