gpt4 book ai didi

linux - 庆典 shell : syntax error near unexpected token `else'

转载 作者:太空宇宙 更新时间:2023-11-04 10:16:09 26 4
gpt4 key购买 nike

<分区>

我正在按照说明执行对我来说似乎很清楚的脚本,在运行它时我被告知第 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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com