Linux 在一个简单的 csh ssh 脚本上获得无与伦比的“.”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10761838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:31:30  来源:igfitidea点击:

Getting unmatched ". on a simple csh ssh script

linuxsshforeachcsh

提问by Dan V

I'm trying to connect to a set of machines using foreach to check whether or not a file exists, however I keep getting the unmatched " error, I've tried plenty of ways and plenty of escape character to try to make it work... however I still get the error, here is the code:

我正在尝试使用 foreach 连接到一组机器来检查文件是否存在,但是我不断收到不匹配的“错误,我尝试了很多方法和大量转义字符来尝试使其工作。 ..但是我仍然收到错误,这是代码:

foreach i ( machineA machineB machineC machineD machineE )
foreach? echo $i":"
foreach? ssh -q $i "\[ -f /etc/init.d/myprog \] \&\& echo \"File exists\" \|\| echo \"File does not exist\""
foreach? end
machineA:
Unmatched ".

Probably something silly, but I've been trying to make it work over the last couple of hours with no success...

可能有些愚蠢,但在过去的几个小时里我一直试图让它工作但没有成功......

The line I'm trying to execute remotely through ssh is this:

我试图通过 ssh 远程执行的行是这样的:

[ -f /etc/init.d/myprog ] && echo "File exists" || echo "File does not exist"

And also tried this way (amongst several other ways):

并且还尝试了这种方式(在其他几种方式中):

foreach? ssh -q -o "BatchMode=yes" $i "[ -f /etc/init.d/netbatch ]" && echo \"File exists\" \|\| echo \"File does not exists\""

Thanks a lot for any help!!!

非常感谢您的帮助!!!

采纳答案by Devon_C_Miller

In my experience, quoting is csh has always been a bit dodgy.

根据我的经验,引用 csh 一直有点狡猾。

Try this:

尝试这个:

foreach i ( machineA machineB machineC machineD machineE )
echo $i":"
ssh -q $i '[ -f /etc/init.d/myprog ] && echo "File exists" || echo "File does not exist"'
end

Nothing is expanded in single quotes which eliminates the need to escape everything.

单引号中没有展开任何内容,因此无需转义所有内容。