I do not have experience working with bash, and I have to update a small script to remove a substring from all the values in a JSON with a common pattern /development/dev/. I get something like this from GetParametersByPath (AWS service):
{
"Parameters": [
{
"Name": "/development/dev/var1",
"Type": "String",
"Value": "Saanvi Sarkar",
"Version": 1
},
{
"Name": "/development/dev/var2",
"Type": "String",
"Value": "Zhang Wei",
"Version": 1
},
{
"Name": "/development/dev/var3",
"Type": "String",
"Value": "Alejandro Rosalez",
"Version": 1
},
]
}
I wanna remove the substring "/development/dev/" for all the Name values.
This is what I have at the moment
// parameter_store_path has the value "/development/dev/"
jq_actions=$(echo -e ".Parameters | .[] | [.Name, .Value] | \042\(.[0])=\(.[2])\042 | sub(\042${parameter_store_path}/\042; \042\042)")
// function that returns the JSON
aws ssm get-parameters-by-path \
--path $parameter_store_path \
--with-decryption \
--region eu-west-2 \
| jq -r "$jq_actions" >> /opt/elasticbeanstalk/deployment/custom_env_var
cp /opt/elasticbeanstalk/deployment/custom_env_var /opt/elasticbeanstalk/deployment/env
#Remove temporary working file.
rm -f /opt/elasticbeanstalk/deployment/custom_env_var
#Remove duplicate files upon deployment.
rm -f /opt/elasticbeanstalk/deployment/*.bak
I was reading some docs about bash, and I saw that I can replace part of the string using ${FOO#prefix}, but I don't know how to implement it in this code.