In my dockerized container I am unable to replace a variable using ‘sed’.
These are my files:
myfile.sql
CREATE TABLE IF NOT EXISTS ${PG_TABLE}(...)
myscript.sh
#!/bin/sh
echo "variable1=${1}"
echo "variable2=${2}"
sed -i "s/${$1}/$2/g" myfile.sql
run command
myscript.sh PG_TABLE "mytablename"
Actual:
- echo variable1=PG_TABLE
- echo variable2=mytablename
- REPLACEMENT:
CREATE TABLE IF NOT EXISTS (…)
Expected:
- echo variable1=PG_TABLE
- echo variable2=mytablename
- REPLACEMENT
CREATE TABLE IF NOT EXISTS mytablename(…)
This is supposed to replace the placeholder with my variable ‘mytablename’, but it just replaces it with empty string.
Maybe its because of my container alpine version.
This is my os.
my docker build operating system
cat /etc/os-release
- PRETTY_NAME=”Debian GNU/Linux 12 (bookworm)”
- NAME=”Debian GNU/Linux”
- VERSION_ID=”12″
- VERSION=”12 (bookworm)”
- VERSION_CODENAME=bookworm
- ID=debian