引用 YAML(对于 Travis CI) [英] Quoting YAML (for Travis CI)
问题描述
如何在 YAML 中转义整行?我想要 json='{"title": "travis_saulshanabrook_site","key": "'$(cat ~/.ssh/id_rsa.pub)'"}'
在列表中,但我无法将其解析为字符串.我可以在整行周围加上单引号,但是我必须转义字符串中的每个单引号,这使得它很难阅读.该字符串将在 Travis CI
How would I escape a whole line in YAML? I want to have json='{"title": "travis_saulshanabrook_site","key": "'$(cat ~/.ssh/id_rsa.pub)'"}'
in a list, but I can't get it to parse into a string. I can put single quotes around the whole line, but then I would have to escape every single quote in my string, making it very hard to read. The string will be run as a bash command in Travis CI
推荐答案
最优雅的解决方案是使用 文字样式 |
指示符,使用 -
修饰符去除最后的换行符.这样就不需要额外的引号.
The most elegant solution is to use the literal style |
indicator, with the -
modifier to strip the final newline. That way there are no extra quotes necessary.
如果这个标量恰好是 YAML 文件中的唯一内容,请使用:
If this scalar happens to be the only thing in a YAML file use:
|-
json='{"title": "travis_saulshanabrook_site","key": "'$(cat ~/.ssh/id_rsa.pub)'"}'
如果是键abc
的映射值:
abc: |-
json='{"title": "travis_saulshanabrook_site","key": "'$(cat ~/.ssh/id_rsa.pub)'"}'
或者如果它是列表的一部分:
or if it is part of a list:
- |-
json='{"title": "travis_saulshanabrook_site","key": "'$(cat ~/.ssh/id_rsa.pub)'"}'
这篇关于引用 YAML(对于 Travis CI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!