Search code examples
sedterraformlaunch-template

What is sed -e expression unknown option to `s`


I have a EC2 userdata bash script with some sed entries as follows. The userdata was base64 encoded as part of a launch template.

sed -i -- "s/{{ data_dir }}/$${CONSUL_DATA_DIR//\//\\\/}/g" $CONSUL_DEFAULT_CONFIG

However I’m getting an error when the instance builds with the below:

sed: -e expression #1, char 39: unknown option to `s'

Solution

  • The -- means end of options, everything following is a file name. The substitution s// that follows is an option, not a file name. Move the -- past the substitution argument. Or maybe it's a typo and you should run sed -i -e "s/.../.../g" $CONSUL_DEFAULT_CONFIG.

    In addition, $$ will be replaced by the shell by the process ID. Is this taken from a Makefile snippet? Then use just one $ when running in the shell and not within a make recipe.