The arguments of the first command given to "bash -c" over ssh is being ignored. xxx at yyy:~$ ssh xxx at localhost bash -c 'echo foo; echo bar' bar xxx at yyy:~$ ssh ova at localhost bash -c ':; echo foo; echo bar' foo bar -- ? ?????????, ????????? ????????????? ???????? ??????-? ????????? ???????? v.olokhtonov at sirena2000.ru
????????? ???????? wrote:> The arguments of the first command given to "bash -c" over ssh is > being ignored. > > xxx at yyy:~$ ssh xxx at localhost bash -c 'echo foo; echo bar' > > barYou should study shell quoting and the SSH protocol. The ssh command is being run in an interactive shell. Your quotes tell this shell that it should pass "echo foo; echo bar" excluding the quotes as a single parameter to the ssh command. As you can see in the SSH protocol, the command to be executed by the server is sent as a single string. In your example that string is "bash -c echo foo; echo bar" excluding the quotes. Try what happens when you run that command directly: $ bash -c echo foo; echo bar bar $ ..and notice that the result is the same. Try to understand why. Now think about what you must do to get your desired result. Understanding quoting is fundamental for actually using the shell, as opposed to copypaste commands from blogs or entering random characters and hoping for the best. There is plenty of good material on the subject, you can start with the bash man page. man bash then search for QUOTING in caps. Shell quoting is also covered in countless books, and probably also in some video tutorials on youtube if that is what you prefer. And of course you must always be aware of which shell is being used where, since quoting works differently in different shells. //Peter
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
????????? ???????? wrote:> The arguments of the first command given to "bash -c" over ssh is > being ignored. > > xxx at yyy:~$ ssh xxx at localhost bash -c 'echo foo; echo bar'Instead of confusing shell quoting I recommend piping the commands to the remote shell. Used judiciously it can avoid confusion. $ echo "echo foo; echo bar" | ssh xxx at example bash Or: $ ssh xxx at example bash <<'EOF' echo foo; echo bar EOF One of the useful features of this method is that the shell interpreter on the remote system is specified and does not use the default login shell from the password file. Useful when your login on some hosts is different than on others. Bob