这是yaml文件:
tasks:
test: {include: [bash_exec], args:['-c', 'state --m=4 in=in4.db | cppextract -f , -P NEW_MODEL /stdin Id Date {a,b,b2}{c,d}L {d1,d2,d3,d4}{x,}y | perl -lane '$F[0] = (shift @F) .".$F[0]"; $, = ":"; print @F;' | state2 --id=Id.Date wq.db -'], answer: '{{out}}/utestt.csv', n: 5, cols: [f,k]} 当分析时,它会产生以下错误:
意外字符($F = (shift @F) .".$F";$,=“”;打印@F;'']
这个命令
state --m=4 in=in4.db | cppextract -f , -P NEW_MODEL /stdin Id Date {a,b,b2}{c,d}L {d1,d2,d3,d4}{x,}y | perl -lane '$F[0] = (shift @F) .".$F[0]"; $, = ":"; print @F;'在linux命令行上提供正确的输出,但在运行yaml时抛出yaml解析器异常。
发布于 2019-10-11 09:16:18
首先,让我们以更易读的格式解开YAML文件:
tasks:
test: {
include: [bash_exec],
args:['-c', 'state --m=4 in=in4.db | cppextract -f , -P NEW_MODEL /stdin Id Date {a,b,b2}{c,d}L {d1,d2,d3,d4}{x,}y | perl -lane '$F[0] = (shift @F) .".$F[0]"; $, = ":"; print @F;' | state2 --id=Id.Date wq.db -'],
answer: '{{out}}/utestt.csv', n: 5, cols: [f,k]
}第一个问题是args:[;YAML要求您将映射值从键中分离出来(除非键是引用的标量)。让我们这样做:
tasks:
test: {
include: [bash_exec],
args: [
'-c',
'state --m=4 in=in4.db | cppextract -f , -P NEW_MODEL /stdin Id Date {a,b,b2}{c,d}L {d1,d2,d3,d4}{x,}y | perl -lane '
$F[0] = (shift @F) .".$F[0]"; $, = ":"; print @F;' | state2 --id=Id.Date wq.db -'
],
answer: '{{out}}/utestt.csv', n: 5, cols: [f,k]
}这就清楚了发生了什么:结束以'state开头的单引号就在$符号之前。由于我们处于YAML流序列(由[启动),解析器希望在该值之后使用逗号或序列的结尾。然而,它找到了一个$,这正是它所抱怨的。
显然,您不希望在$之前停止标量;'应该是内容的一部分。实现这一点有多种方法,但最易读的方法可能是将值定义为块标量:
tasks:
test:
include: [bash_exec]
args:
- '-c'
- >-
state --m=4 in=in4.db | cppextract -f ,
-P NEW_MODEL /stdin Id Date {a,b,b2}{c,d}L {d1,d2,d3,d4}{x,}y |
perl -lane '$F[0] = (shift @F) .".$F[0]"; $, = ":"; print @F;' |
state2 --id=Id.Date wq.db -
answer:
- '{{out}}/utestt.csv',
- n: 5
- cols: [f, k]>-启动流标量,该标量可以跨越多行,并将分行符折叠到一个空格字符中。请注意,我删除了周围的流映射({…}),并将其替换为块映射,以便能够在其中使用块标量。
我还将answer更改为当前不是的序列,但它看起来应该是(在您显示的YAML中也是错误的)。
https://stackoverflow.com/questions/58332282
复制相似问题