Lets suppose I've this
a: "ABC"
b: *a
I want b
to have the same content than a
, keep in mind that a is an string, not an array.
is this possible?
Concatenating strings and/or variablesThe standard YAML format does not support the notion of string concatenation. Since concatenating string values is a common pattern in easyconfig files, the EasyBuild framework defines the ! join operator to support this.
YAML example¶ We can use the ampersand & character to create a named anchor, that we can then reference later on with an asterisk *. Anchor names must not contain the [, ], {, } and , characters. This came in use when I had to create some elasticsearch mappings that were being duplicated all over the place.
What Is An Anchor? YAML anchors are a feature which let you identify an item and then reference it elsewhere in your file. Anchors are created using the & sign. The sign is followed by an alias name. You can use this alias later to reference the value following the anchor.
Yes, that's called an alias.
You make an Anchor with &anchorname
and refer to it with *anchorname
a: &a "ABC"
b: *a
You can also use an array to define many aliases which is quite succinct.
aliases:
- &foo "foo"
- &bar "bar"
test1: *foo
test2: *bar
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