quote
not recommanded:
Script:
- "echo \"hh\" > /test.txt"
recommanded:
Script:
- echo "hh" > /test.txt
YAML的字符串不需使用引号,这可以增加可读性,并避免嵌套的转义字符;即所见即所得。
然而,这有时也会导致错误,例如,字符串本身是一个暧昧的字眼(像数字或布尔值);或在短句中意外的出现YAML的结构符号(常见的例子是由惊叹号起始的句子,或是包含冒号-空白的句子:"!Caca de vaca!"、"Caution: lions ahead")。这在发布YAML文件时并不造成困扰,但在制作小型脚本和人工编辑文件时,这问题却会常常出现。比较好的方法是善用区块符号("|" or ">")而不要使用单行字符串,来避免这种暧昧的表示方法,"|" or ">"会告诉yaml,接下来的内容全是字符串
Slogan:
- >
caution: wet
multiline string
If you want to use a folded scalar:
foo:
- bar
- bar2
- >
super duper long
string that I would like
to have on multiple lines
- Another item
Note that there may not be content on the line of the folded scalar's header (the line with the >).
Alternatively, you can just use a plain scalar:
foo:
- bar
- bar2
- super duper long
string that I would like
to have on multiple lines
- Another item
所以yaml的plain scalar和 > 是等价的
网友评论