简体   繁体   中英

Heredoc for nested command in bash

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?

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'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM