I am trying to execute below script in remote machine but the output is not adding '\n' while executing sed command. But if I execute same sed command outside its working fine. I tried adding \$ in the sed command thats not adding \n to the output. Any thoughts ?
set -e
set -o pipefail
ssh "$host" << EOF
temp_working_dir=/tmp/working_dir
mycert_path=\${temp_working_dir}/mycert/
cert=\$(cat "\${mycert_path}"/cert.pem | sed 's/$/\\n/' | tr -d '\n')
echo "\$cert" > /tmp/cert
EOF
CodePudding user response:
escaping escapes is tiring.
your sed script needs yet one more escaping backslash: 's/$/\\n/g'
set -e
set -o pipefail
ssh "${host}" << EOF
temp_working_dir=/tmp/working_dir
mycert_path=\${temp_working_dir}/mycert
cert=\$(sed 's/$/\\\n/g' "\${mycert_path}/cert.pem" | tr -d '\n')
echo "\$cert" > /tmp/cert
EOF