I have a repository that uses Travis CI
, and in the .travis.yml
there I have this line:
script: - vim -Nu <(cat <<-EOF set nocompatible | filetype off EOF ) -c 'Script' > /dev/null
Sadly this doesn't work, as this is transformed into a single line and is executed like this:
vim -Nu <(cat <<-EOF set no compatible | filetype off | EOF ) -c 'Script' > /dev/null
This makes the EOF
tag not working, as EOF
needs to be in a single line. An alternative would be to just use normal quotes like this:
script: - vim -Nu <(cat 'set nocompatible | filetype off ) -c 'Script' > /dev/null
Which works, and is fine, but I feel there must be a way to insert newlines into a .travis.yml
. I have an alternative now, but I may not in the future. So how do you do it?
Using a Backslash. The backslash (\) is an escape character that instructs the shell not to interpret the next character. If the next character is a newline, the shell will read the statement as not having reached its end. This allows a statement to span multiple lines.
The pipe is used when you want newlines to be kept as newlines.
In YAML you can specify newlines in a scalar by using ""
quoting and escaping the newlines (\n
), or, and that is more natural for your case, by using a literal style block scalar:
script: - | vim -Nu <(cat <<-EOF set nocompatible | filetype off EOF ) -c 'Script' > /dev/null
This is a scalar starting with a line with a |
(pipe symbol), followed by multiple lines for which the line-breaks are preserved.
|
there can be modifiers: 1
-9
, used when your first line starts with spaces; +
, -
to influence stripping of final newlines (normally collapsed into one).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With