ssh "bash -c" bug

Phil Pennock phil.pennock at globnix.org
Thu Feb 21 07:46:58 EST 2013


On 2013-02-20 at 19:17 +0400, Олохтонов Владимир wrote:
> The arguments of the first command given to "bash -c" over ssh is being 
> ignored.

SSH does not send an array/vector in the protocol; instead, it joins
together the options into one command-line, sent to be run on the remote
side.

When you write:

  bash -c 'echo foo; echo bar'

this provides three parameters to the local command, joined back
together *without* quoting to protect the original parameters.  So you
might as well have written:

  'bash -c echo foo; echo bar'

So treat the combination of the parameters you write as something to be
parsed apart by shell again, since the client doesn't preserve the
structure of the original command-line.

With a perspective of "command prefices, and preserve the command
array" (like "nice", "nohup", any other command-that-takes-a-command),
ssh's behaviour is a bug.  But it's long-standing, and changing it would
break existing tools, so it's behaviour that you have to live with.

Regards,
-Phil


More information about the openssh-unix-dev mailing list