Using a bash script to process a file and pass it to AWS CLI. The script runs inside a docker container.
I'm using sed to do template string replace. When MY_VALUE
contains special chars. (eg: MY_VALUE="http://aaa.com"
) the sed command fails.
This makes me question if sed is the right tool for this job, don't have a lot of control on the values that come in.
Because the template is a JSON file, I considered trying JQ or Python (something like this).
I haven't used bash or Unix tools a lot so I would like to hear your thoughts on:
- Is
sed
the right tool for this type of job? - What else would you use?
- What do you think about the script?
Simplified template (JSON)
{
"networkMode": "bridge",
"name": "[Placeholder.A]"
}
Script
#!/bin/bash
MY_VALUE=${myvalue}
rm -f processed.json
cat /app/template.json | \
sed s/\\[Placeholder.A]/${MY_VALUE}/ > /app/processed.json
aws cli command -file processed.json
/
, which are the character that sed uses to separate the blocks of a replacement:sed 's/find/replace/'
. The first, easy, step is to change the separator into another one:sed 's_find_replace_'
for example with_
. \$\endgroup\$_
) \$\endgroup\$