mirror of
https://github.com/jbranchaud/til
synced 2026-01-02 22:58:01 +00:00
Add Create Multi-Line Strings Without The Line Breaks as a yaml til
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
||||
|
||||
_1057 TILs and counting..._
|
||||
_1058 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -58,6 +58,7 @@ _1057 TILs and counting..._
|
||||
* [VSCode](#vscode)
|
||||
* [Webpack](#webpack)
|
||||
* [Workflow](#workflow)
|
||||
* [YAML](#yaml)
|
||||
|
||||
---
|
||||
|
||||
@@ -1242,6 +1243,10 @@ _1057 TILs and counting..._
|
||||
- [Update asdf Plugins With Latest Package Versions](workflow/update-asdf-plugins-with-latest-package-versions.md)
|
||||
- [View The PR For The Current GitHub Branch](workflow/view-the-pr-for-the-current-github-branch.md)
|
||||
|
||||
## YAML
|
||||
|
||||
- [Create Multi-Line Strings Without The Line Breaks](yaml/create-multi-line-strings-without-the-line-breaks.md)
|
||||
|
||||
## Usage
|
||||
|
||||
The `.vimrc` file for this project contains a function `CountTILs` that can
|
||||
|
||||
22
yaml/create-multi-line-strings-without-the-line-breaks.md
Normal file
22
yaml/create-multi-line-strings-without-the-line-breaks.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Create Multi-Line Strings Without The Line Breaks
|
||||
|
||||
There are [many ways](https://stackoverflow.com/a/21699210/535590) 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 `|-`.
|
||||
|
||||
```yaml
|
||||
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.
|
||||
Reference in New Issue
Block a user