Closed davidak closed 8 years ago
You have an unquoted dangling :
in grep model\ name /proc/cpuinfo | head -1 | cut -f2 -d:
.
Actually, the error is on line 4… There is a trailing space after :
that's fooling the parser. Try quoting the entire string:
before_install:
- printf "CPU:"
- grep model\ name /proc/cpuinfo | head -1 | cut -f2 -d:
- "printf CPU Cores: "
- grep -c processor /proc/cpuinfo
Or drop the space. (This makes the parser pass, but the data structure would be different.
{
"before_install": [
"printf \"CPU:\"",
{
"grep model\\ name /proc/cpuinfo | head -1 | cut -f2 -d": null
},
{
"printf CPU Cores": null
},
"grep -c processor /proc/cpuinfo"
]
}
I should note that the second command does not do what you think it does. (See the comment above.)
i noted that myself as there was not the output i wanted. i quoted it.
what you call "fooling the parser" should get fixed since i used the correct syntax.
thanks for the fast answers!
Not sure how you came to the conclusion that this is valid YAML syntax.
$ pry
[1] pry(main)> require 'yaml'
=> true
[2] pry(main)> yaml = <<-EOF
[2] pry(main)* before_install:
- printf "CPU:"
- grep model\ name /proc/cpuinfo | head -1 | cut -f2 -d:
- printf "CPU Cores: "
[2] pry(main)* - printf "CPU:"nfo[2] pry(main)* - printf "CPU:"
- grep model\ name /proc/cpuinfo | head -1 | cut -f2 -d:
- printf "CPU Cores: "
[2] pry(main)* - grep model\ name /proc/cpuinfo | head -1 | cut -f2 -d:roc/cpuinfo | head -1 | cut -f2 -d:
- printf "CPU Cores: "
[2] pry(main)* - printf "CPU Cores: "pry(main)* - printf "CPU Cores: "
[2] pry(main)* - grep -c processor /proc/cpuinfo - grep -c processor /proc/cpuinfo
[2] pry(main)* EOF
=> "before_install:\n - printf \"CPU:\"\n - grep model name /proc/cpuinfo | head -1 | cut -f2 -d:\n - printf \"CPU Cores: \"\n - grep -c processor /proc/cpuinfo\n"
[3] pry(main)> YAML.load(yaml)
Psych::SyntaxError: (<unknown>): found unexpected end of stream while scanning a quoted scalar at line 4 column 24
from /Users/asari/.rvm/gems/ruby-2.1.5/gems/psych-2.0.8/lib/psych.rb:370:in `parse'
You may also try http://yaml-online-parser.appspot.com/ for validation.
as i understand i can use colons if i quote the string. is it official part of the syntax, that this is only true if there is not a whitespace after it?
I think this is not an error since it is quoted.