I have a yaml file and shell script to edit the values of yaml file.
#YAML
UI:
repo: my-repo-1
imageTag: ui-image:v1
DB:
repo: my-repo-2
imageTag: db-image:v1
#!/bin/bash
sed -i "/^\([[:space:]]*imageTag: \).*/s//\1$1/" test.yaml
On running the script to change the tag of UI with ./script.sh ui-image:v2 is changing the imageTag of both UI and DB with value "ui-image:v2".
How can I make a change in the script so that I can pass individual tag to both UI and DB
CodePudding user response:
You can limit the replacement for $1
to "from UI: to imageTag:" and similarly for DB:
and $2
:
sed -i -e "/^UI:/,/imageTag:/{/^\([[:space:]]*imageTag: \).*/s//\1$1/}" \
-e "/^DB:/,/imageTag:/{/^\([[:space:]]*imageTag: \).*/s//\1$2/}" \
test.yaml