<分区>
我正在按照说明执行对我来说似乎很清楚的脚本,在运行它时我被告知第 36 行有错误。似乎无法理解问题。
line 36: syntax error near unexpected token `else'
line 36: ` else'
代码:
if [ "$answer" = "y" ] #Backup all VMs if answer is yes
then
for num in 1 2 3 #Determiant loop for 3 arguments: 1, 2, and 3
do
echo "Backing up VM #$num"
gzip < /var/lib/libvirt/images/centos$num.qcow2 > /root/centos$num.qcow2.backup.gz
echo "VM #$num BACKUP DONE"
done
elif [ "$answer = "n" ]
then
read -p "Which VM should be backed up? '(1/2/3)': " numanswer
until echo "$numanswer" | grep "^[123]$" >> /dev/null # Look for match of single digit: 1, 2, or 3
do
read -p "Invalid Selection. Select 1,2, or 3: " numanswer
echo "Backing up VM #$numanswer"
gzip < /var/lib/libvirt/images/centos$numanswer.qcow2 > /root/centos$numanswer.qcow2.backup.gz
echo "VM #$numanswer BACKUP DONE":
else ### line 36
echo "Invalid Selection... Aborting program"
exit2
fi