1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00
Files
til/yaml/create-multi-line-strings-without-the-line-breaks.md

782 B

Create Multi-Line Strings Without The Line Breaks

There are many ways to add multi-line strings to a YAML document. Most of them preserve the literal newlines present in the multi-line string. And generally that is what you want in a multi-line string.

Sometimes, however, you want a multi-line string just for its readability in the file. The literal representation of the string should exclude the newlines. To achieve this, you can use either >- or |-.

run: >-
  echo "::set-output name=NODE_VERSION::$(
    cat .tool-versions
    | grep nodejs
    | sed 's/nodejs \(.*\)$/\1/'
  )"

This creates a readable key-value pair without introducing newline characters into the string that represents a shell command.