我试图连接到一组机器使用FROACH检查文件是否存在,但是我不断得到“无与伦比的”错误,我已经尝试了很多方法和大量的转义字符,使其工作…但是我仍然得到错误,下面是代码:
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 ".
可能有些愚蠢的事情,但我在过去的几个小时里一直在努力让它成功…
我试图通过ssh远程执行的行是:
[ -f /etc/init.d/myprog ] && echo "File exists" || echo "File does not exist"
也尝试过这种方式(包括其他几种方式):
foreach? ssh -q -o "BatchMode=yes" $i "[ -f /etc/init.d/netbatch ]" && echo \"File exists\" \|\| echo \"File does not exists\""
非常感谢你的帮助!!!
最佳答案
以我的经验,引用是csh总是有点狡猾。
试试这个:
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
没有任何东西可以用单引号来扩展,这样就不需要逃避一切。