I tried to replace private.pem with cat command but I get an error.
How can I avoid this error?
■ shell script
#!/bin/bash
privateKey=$(cat private.pem)
replacedKey=$(awk '{printf "%s\\n", $0}' private.pem)
echo $replacedKey
sed -e "s|PRIVATE_KEY: .*$/PRIVATE_KEY: $(echo $replacedKey)|g" ./docker-compose.yaml
■ error (macOS)
sed: 1: "s|PRIVATE_KEY: .*$/PRIV ...": unterminated substitute pattern
CodePudding user response:
You should not use such way. Because cert key files are include "/" character which causes issue on sed parameter separator. What is best practice use additional environment variable to pass to docker-compose and always replace variable content on air.
- Abother interesting way you can use
envsubst
command.
privateKey=$(cat private.pem)
replacedKey=$(awk '{printf "%s\\n", $0}' private.pem) envsubst < docker-compose.yaml