Heredoc for nested command in bash

强颜欢笑 提交于 2020-01-24 10:34:05

问题


I need to ssh into a machine and execute a bunch of commands under sudo bash. Here is what I've tried:

sshpass -p "vagrant" ssh vagrant@33.33.33.100 "sudo bash -i -c <<EOF
    echo
    ls
    echo
EOF"

But it throws me 'bash: -c: option requires an argument\n'. How can I fix this?


回答1:


You need to remove -c from your command line to make it accept heredoc:

sshpass -p "vagrant" ssh vagrant@33.33.33.100 "sudo bash <<EOF
    echo
    ls
    echo
EOF"

Also you may remove -i (interactive) option too.

bash -c expects you to provide all commands on command line so this may work too:

sshpass -p "vagrant" ssh vagrant@33.33.33.100 "sudo bash -c 'echo; ls; echo'"


来源:https://stackoverflow.com/questions/27012174/heredoc-for-nested-command-in-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!