I have several files that I need to update accross several directories. Normally I would do that with a bash loop. I was trying to do the same with YQ, but with no luck.
Just to point out, since the question's been flagged as a duplicate of "Bash: difference between single and double quotes" - this is not a question about bash syntax, but yq syntax.
I was hoping this would work:
for i in one two three four;
do
yq -i '.key = "$i-something"' ./$i/file.yaml;
done
This would, however, store the literal value of what's been given, so it would be key: $i-something
, which is not what I need. I would need it to be like key: one-something
.
If I tried switching the quotes, like yq -i ".key = '$i-something'" ./$i/file.yaml;
that would produce an error stating Error: 1:12: invalid input text "'one..."
Any ideas?
CodePudding user response:
You need to use double quotes in both places:
for i in one two three four; do
yq -i ".key = \"$i-something\"" ./$i/file.yaml;
done