command [argument ...] in ssh(1): a footgun

Brian Candler b.candler at pobox.com
Sat May 27 17:53:50 AEST 2023


On 27/05/2023 01:45, Thorsten Glaser wrote:
>>   ssh user at host "ls -l a\ b"
> This one, incidentally, sends 'ls -l a b' to the remote shell.
>     ssh user at host "ls -l a\\ b"
> has the effect you want; the first backslash is eaten by the
> local shell.
>
Or is it?

$ echo "ls -l a\ b"
ls -l a\ b
$

This is with bash 5.2.15. From the man page:

        Enclosing characters in double quotes preserves the literal  value
        of  all  characters within the quotes, with the exception of $, `,
        \, and, when history expansion is enabled, !.
...
        The backslash
        retains its special meaning only when followed by one of the  fol-
        lowing  characters:  $, `, ", \, or <newline>.

Other shells may be different, of course.

Regards,

Brian.


More information about the openssh-unix-dev mailing list