Skip to content

Appending the array of strings to a yaml list #221

Answered by TomWright
paradajz asked this question in Q&A
Discussion options

You must be logged in to vote

The dasel command you're looking for is:

$ dasel put string -f test.yaml -o - "list.[]" "line4"
list:
- line1
- line2
- line3
- line4

Note that to append we use the [] selector rather than [$i]. Using [$i] you will be overwriting the value at that index.

$ dasel put string -f test.yaml -o - "list.[1]" "line4"
list:
- line1
- line4
- line3

Here's an example run.sh that will append the bash array items to test.yaml and write the results to test.out.yaml:

#!/bin/bash

filename=test.yaml
out_filename=test.out.yaml

# new items to be added to the list
array=(line4 line5 line6)

# copy filename contents to out_filename.
cp $filename $out_filename

for ((i=0;i<${#array[*]};i++))
do
    {
       …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@TomWright
Comment options

Answer selected by paradajz
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants