Bash中嵌套命令的Heredoc [英] Heredoc for nested command in bash
本文介绍了Bash中嵌套命令的Heredoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要ssh进入机器并在 sudo 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"
但是它让我'bash:-c:option需要一个参数\ n'
.我该如何解决?
But it throws me 'bash: -c: option requires an argument\n'
. How can I fix this?
推荐答案
您需要从命令行中删除 -c
,以使其接受heredoc:
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"
此外,您也可以删除 -i
(交互式)选项.
Also you may remove -i
(interactive) option too.
bash -c
希望您在命令行上提供所有命令,因此也可以使用:
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'"
这篇关于Bash中嵌套命令的Heredoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文