Sebastian Luhnburg wrote on Fri, Jun 30, 2023 at 03:47:57PM +0200:
> /bin/bash -c "echo 'password in subshell in here document: ' ${password@Q}"
${password@Q} is still within double quotes in your here-document here;
these quotes are breaking the escaping you used.
This would be out of quotes:
bash <<EOF
bash -c "echo 'password in subshell in here document: ' " ${password@Q}
EOF
(And if you want to actually print the backslashes here you'll need a
third level of escaping with printf %q or @Q, but that is really just
for echo)
But..
> p.s.: in the final script, it is only one SSH:
>
> ssh user@machine << EOF
> /bin/bash -c "do something with the password"
> EOF
then as Greg suggested pass password to bash as argument instead;
assuming password has been quoted once as previously:
ssh user@machine << EOF
bash -c 'echo \$1' -- $password
EOF
(note once again it should not be quoted, printf %q or ${@Q} did that)
And... if that is all there is to it ssh already runs things in a shell,
so you don't need bash -c at all and can just use $password directly,
quoted exactly once.
--
Dominique