shell脚本中获取远程文件时出错
我有这个脚本正在 4 台服务器上执行 scp 并在调用服务器上获取文件,但是当我运行它时,出现以下错误:
syntax error near unexpected token `then'
line 16: `if[[ $line = $texts ]] ; then
代码如下:
#!/bin/sh
servers=("[email protected]" "[email protected]" "[email protected]" "[email protected]")
tlen=${#servers[@]}
count=o
total=0
texts="Untar done you can upload new .tar file"
for(( i=0; i<${tlen}; i++ ));
do
echo "in"
scp ${servers[$i]}:/usr/site/html/test/test.txt /mnt/backups/updateimage
cat test.txt ; while read line
do
echo "in"
let count++
echo "$line"
if[[ $line = $texts ]] ; then
echo "true"
let total++
else echo "false"
fi
done < test.txt
done
exit 0
I have this script that is doing a scp onto 4 servers and getting the file on the calling server , but when I run it I get the following error:
syntax error near unexpected token `then'
line 16: `if[[ $line = $texts ]] ; then
The code is as follows:
#!/bin/sh
servers=("[email protected]" "[email protected]" "[email protected]" "[email protected]")
tlen=${#servers[@]}
count=o
total=0
texts="Untar done you can upload new .tar file"
for(( i=0; i<${tlen}; i++ ));
do
echo "in"
scp ${servers[$i]}:/usr/site/html/test/test.txt /mnt/backups/updateimage
cat test.txt ; while read line
do
echo "in"
let count++
echo "$line"
if[[ $line = $texts ]] ; then
echo "true"
let total++
else echo "false"
fi
done < test.txt
done
exit 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
if
和[[
编辑
之间添加一个空格我刚刚运行了此测试,它的正确计算结果为 false
我怀疑您的问题出在其他地方
Put a space between
if
and[[
EDIT
I've just ran this test and it properly evaluates to false
I suspect your problem is elsewhere