Bash错误:" b.sh:第52行:语法错误:意外的文件注销结束"

时间:2015-01-29 20:22:14

标签: macos bash ssh scp eof

所以,我希望这能从我的电脑下载文件,将其传输到我的iPhone,在那里安装文件,然后重新打电话。出于某种原因,您在标题中看到的错误会弹出。如果有人可以提供帮助,那会很好,谢谢。

#!/bin/bash
clear
cd downloads
if [ ! -d ".tmpdl" ]; then
  mkdir ".tmpdl"
fi
cd .tmpdl
echo "Enter .deb link:"
read dllink
echo "Enter name of tweak (simple):"
read name
echo "Enter IP of device:"
read IP
echo "Enter your SSH password. If you don't know what this is enter 'alpine' without the apostrophes."
read pass
echo "Sending test file..."
touch test.txt
sshpass -p "$pass" scp test.txt root@"$IP":/var/mobile/Documents
echo "If the transfer was successful (no permission denied error) enter yes or no if it wasn't."
read reply1
if [ $reply1 == no ]; then
 echo "Error, wrong credentials, try again."
 exit
fi
echo "Okay, attempting to download file..."
curl -o "$name".deb "$dllink"
if [ ! -d "tmp" ]; then
  sshpass -p "$pass" ssh root@"$IP" << EOF
   cd /
   cd var/mobile/Documents
   mkdir tmp
 EOF
fi

sshpass -p "$pass" scp "$name".deb root@192.168.1.104:/var/mobile/Documents/tmp
echo "Sent file, deleting it from here..."
cd ..
rm -rf .tmpdl
sshpass -p "$pass" ssh root@"$IP" << EOF
  cd /
  cd var/mobile/Documents
  mkdir tmp
  mv "$name".deb tmp/
  cd tmp
  dpkg -i "$name".deb
  echo "Clearing caches..."
  cd ..
  rm -rf tmp
  echo "Done installing, respringing now..."
  killall backboardd
EOF

1 个答案:

答案 0 :(得分:1)

这些行:

if [ ! -d "tmp" ]; then
  sshpass -p "$pass" ssh root@"$IP" << EOF
   cd /
   cd var/mobile/Documents
   mkdir tmp
 EOF
fi

有问题。 EOF不在行的开头(缩进一个空格),因此它不是here-doc的结尾,因此here-doc直到文件结尾才会终止(恰好是第二个EOF,它应该终止第二个here-doc),并生成错误消息,因为if没有以fi终止。 Unindent EOF,你应该开展业务。