Information Technology Reference
In-Depth Information
replaced with the evaluated content of a variable. In the following example,
#{x}
is used to
insert the value of
x
within a string.
Both double and single-quoted strings use the backslash (
\
) character to escape special char-
acters.
"double quoted string"
#=> "double quoted string"
'single quoted string'
#=> "single quoted string"
x
=
"hello"
"
#{
x
}
world"
#=> "hello world"
'#{x} world'
#=> '#{x} world'
"quotes in \\"quotes\\""
#=> "quotes in \"quotes\""
'quotes in \'quotes\''
#=> "quotes in \"quotes\""
Double-quoted strings interpolate
Si
ngle-quoted strings use the literal
You might need to escape special characters. For example, when storing the player name
Jim O'Rourke
as a string, you need to escape the single quote in his last name:
player
=
'Jim O\'Rourke'
Alternatively, you can use double quotes and avoided escaping the character altogether:
player
=
"Jim O'Rourke"
Heredoc Notation
In Chef, you might see the “heredoc” notation for strings. Heredoc is especially useful
when having a multiline string. Heredoc notation starts with two “less than” symbols (
<<
)
and then some identifier. The identifier can be any string, but should not be a string that
is likely to appear in the body of text. In the following example, we chose
METHOD_DESCRIPTION
as the heredoc identifier: