Bug 17251 - someone eats the 1st line of "bash -c 'echo aaa; echo bbb; echo ccc'"
Summary: someone eats the 1st line of "bash -c 'echo aaa; echo bbb; echo ccc'"
Status: CLOSED NOTABUG
Alias: None
Product: Branch 4.0
Classification: Distributions
Component: openssh-server (show other bugs)
Version: 4.0
Hardware: all Linux
: P2 normal
Assignee: Dmitry V. Levin
QA Contact: Q.A. 4.0
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-21 18:14 MSD by Ivan Zakharyaschev
Modified: 2008-09-22 16:40 MSD (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Zakharyaschev 2008-09-21 18:14:15 MSD
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
$
Comment 1 Ivan Zakharyaschev 2008-09-21 18:17:45 MSD
This is also true for:
openssh-server-3.6.1p2-alt1
openssh-clients-3.6.1p2-alt1
bash-3.1.17-alt1
Comment 2 Dmitry V. Levin 2008-09-21 19:31:24 MSD
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'"
Comment 3 Ivan Zakharyaschev 2008-09-22 07:11:43 MSD
(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.
Comment 4 Dmitry V. Levin 2008-09-22 14:49:16 MSD
(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"
Comment 5 Ivan Zakharyaschev 2008-09-22 16:39:59 MSD
(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').