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


i'm following instructions on implementing script seemed clear me, upon running i'm told there error line 36. can't seem understand problem.

line 36: syntax error near unexpected token `else' line 36: `  else' 

the code:

   if [ "$answer" = "y" ] #backup vms if answer yes             num in 1 2 3 #determiant loop 3 arguments: 1, 2, , 3             echo "backing 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" ]             read -p "which vm should backed up? '(1/2/3)': " numanswer    until echo "$numanswer" | grep "^[123]$" >> /dev/null # match of single digit: 1, 2, or 3              read -p "invalid selection. select 1,2, or 3: " numanswer           echo "backing 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 

the script should read:

 27 elif [ "$answer = "n" ]  28  29     read -p "which vm should backed up? '(1/2/3)': " numanswer  30     until echo "$numanswer" | grep "^[123]$" >> /dev/null # match of single digit: 1, 2, or 3  31      32         read -p "invalid selection. select 1,2, or 3: " numanswer  33     done  34     echo "backing vm #$numanswer"  35     gzip < /var/lib/libvirt/images/centos$numanswer.qcow2 > /root/centos$numanswer.qcow2.backup.gz  36     echo "vm #$numanswer backup done":  37 else  38     echo "invalid selection... aborting program"  39     exit2  40 fi 

note done in 33, needed.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -