A developer is writing a YAML file for deployment and needs to preserve the line breaks in a multiline variable. Which technique accomplishes this requirement?
Separate each line into its own element within a sequence
Use backslash characters to join the lines in a single line
Enclose the multiline content within curly braces for storage
Apply an indented literal block for the multiline data
Using a literal block scalar introduced by the pipe (|) character keeps every newline exactly as written, so the entire text is stored in one variable with its original formatting. YAML does not treat a backslash as a line-continuation symbol, so inserting backslashes would leave the newline characters intact and fail to join the lines. Splitting the text into separate sequence elements would create multiple variables, and enclosing the content in curly braces would define a flow mapping rather than a multiline scalar.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is an indented literal block?
Open an interactive chat with Bash
Why can’t backslashes be used to preserve multiline variables?
Open an interactive chat with Bash
How do sequences differ from literal blocks for multiline variables?