openssh-server-4.7p1-alt1 openssh-clients-4.7p1-alt1 bash-3.1.17-alt3 The first line of output disappears: $ ssh 0 bash -c 'echo aaa; echo bbb; echo ccc' Enter passphrase for key '/home/imz/.ssh/id_rsa': bbb ccc $ But it puzzlingly happens only for bash over ssh. Other combinations of the commands work well: $ ssh 0 echo a Enter passphrase for key '/home/imz/.ssh/id_rsa': a $ bash -c 'echo aaa; echo bbb; echo ccc' aaa bbb ccc $ bash --login -c 'echo aaa; echo bbb; echo ccc' aaa bbb ccc $
This is also true for: openssh-server-3.6.1p2-alt1 openssh-clients-3.6.1p2-alt1 bash-3.1.17-alt1
The ssh protocol passes command line as a string. That is, all ssh args gets merged into one space separated string and passed to the server side, where sshd executes shell -c string. Compare: ssh 0 bash -c 'echo aaa; echo bbb; echo ccc' and ssh 0 "bash -c 'echo aaa; echo bbb; echo ccc'"
(In reply to comment #2) Thanks for the answer! > Compare: > ssh 0 bash -c 'echo aaa; echo bbb; echo ccc' > and > ssh 0 "bash -c 'echo aaa; echo bbb; echo ccc'" > And: $ bash -c "bash -c echo aaa; echo bbb; echo ccc" bbb ccc $ bash -c 'echo $1 $2' 0 1 2 1 2 $ Now it's clear.
(In reply to comment #3) > $ bash -c "bash -c echo aaa; echo bbb; echo ccc" This command does the same as bash -c "bash -c echo; echo bbb; echo ccc"
(In reply to comment #2) > The ssh protocol passes command line as a string. > That is, all ssh args gets merged into one space separated string and > passed to the server side, where sshd executes shell -c string. Actually, the usage format "ssh hostname command [arg]..." is not documented, so it it was not correct for me to expect a certain behavior from this undocumented feature. The manpage shows just a single command argument. Now I see that this format is confusing, and the problem would be obvious if I used a single command argument as suggested by the manpage (ssh imz@etik 'bash -c echo a; echo b; echo c').