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?

Thorsten Glaser t.glaser at tarent.de
Sun Jan 12 04:20:28 AEDT 2020


On Sat, 11 Jan 2020, Yuri wrote:

> On 2020-01-11 09:07, Thorsten Glaser wrote:
> > Yes, “command1” is expanded remotely, but you use the quoting rules
> > of the remote shell INSIDE the single quotes for the local POSIX shell
> > to prevent that (just replace all ' with '\'' and you’re set).
> 
> It arrives to the remote host with the outer quotes stripped, and the
> expansion takes place.

No, it doesn’t.

$ ssh localhost 'echo "a  string with '\'' and" '\''$pecial ch`aracters'\''  works'
a  string with ' and $pecial ch`aracters works

The command that gets run remotely is:
	echo "a  string with ' and" '$pecial ch`aracters'  works

This is handled according to normal quoting rules on the remote side,
as if you entered it interactively.

bye,
//mirabilos, shell developer (so knows what he’s saying)
-- 
tarent solutions GmbH
Rochusstraße 2-4, D-53123 Bonn • http://www.tarent.de/
Tel: +49 228 54881-393 • Fax: +49 228 54881-235
HRB 5168 (AG Bonn) • USt-ID (VAT): DE122264941
Geschäftsführer: Dr. Stefan Barth, Kai Ebenrett, Boris Esser, Alexander Steeg


More information about the openssh-unix-dev mailing list