Why are the arguments supplied for the command run through ssh interpreted by shell before they are passed to the command on the server side?

Darren Tucker dtucker at dtucker.net
Sat Jan 11 20:38:06 AEDT 2020

On Sat, 11 Jan 2020 at 12:46, Yuri <yuri at rawbw.com> wrote:

> If "echo" is interpreted as a login shell, who interprets "`hostname`"
> as "remote-host-name" then, and why?

Echo is not used as a login shell.

In both cases it uses your shell, the difference being that in the "ssh
foo" case it runs a shell with arguments indicating it's an interactive
login (ie a "login shell" which is indicated by a leading "-" in its argv,
and usually enables features like job control).  In the other case, it's
run via the shell using $SHELL -c "your command".

> I found that in order to pass the string to the command run on the
> remote host verbatim it is necessary to escape every character in it,
> but it isn't clear why should this be necessary.

The command you give is always handled on the server by your shell in some
fashion.  It has to be, because SSH only specifies an opaque string for the
remote command, so without doing so you would not be able to specify
arguments at all.

Darren Tucker (dtucker at dtucker.net)
GPG key 11EAA6FA / A86E 3E07 5B19 5880 E860  37F4 9357 ECEF 11EA A6FA (new)
    Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.

More information about the openssh-unix-dev mailing list