The first command of a nested compound command receives no arguments

Parke parke.nexus at gmail.com
Sun Oct 21 16:54:55 AEDT 2018


Hello,

The following three commands work as expected:

root at cosmic:~# ssh localhost 'echo 1 && echo 2 && echo 3'
1
2
3
root at cosmic:~# ssh localhost "dash -c 'echo 1 && echo 2 && echo 3'"
1
2
3
root at cosmic:~# ssh localhost echo 1 2 3 4 5
1 2 3 4 5

The following three commands produce unexpected behavior.
Specifically, it appears that the first nested command is called with
no arguments.

root at cosmic:~# ssh localhost dash -c 'echo 1 && echo 2 && echo 3'

2
3
root at cosmic:~# ssh localhost dash -c 'touch a && touch b && touch c'
touch: missing file operand
Try 'touch --help' for more information.
root at cosmic:~# ssh localhost dash -c 'touch a b && touch c d && touch e f'
touch: missing file operand
Try 'touch --help' for more information.

Is the above the intended behavior?  If so, why?  What is going on?
It seems strange to me.

The above commands were run on Ubuntu 18.10 on a VPS at Digital Ocean.
The openssh package version appears to be: 1:7.7p1-4.

Another pair of examples:

root at cosmic:~# ssh localhost dash -c 'hostname && hostname && hostname'
cosmic
cosmic
cosmic
root at cosmic:~# ssh localhost dash -c 'echo `hostname` && echo
`hostname` && echo `hostname`'

cosmic
cosmic

Another strange example:

root at cosmic:~# ssh localhost dash -c 'exit 2 && exit 3 && exit 4'
(Will exit with status of 3.)

Thank you,

Parke


More information about the openssh-unix-dev mailing list