2013-07-01 84 views
0

当我使用多个if-else时,我仍然收到一些语法错误。请帮助无法正确输出if-else循环

stats=$(rpm -qa | grep MySQL) 
set -f # turn off globbing, so as not to expand wildcards 
arr=($(echo "$stats" | sed 's/,/ /g')) 
if [[ "${arr[0]}" == "MySQL-server-5.6.11-2.rhel5" ]] && [[ "${arr[1]}" == "MySQL-client-5.6.5_m8-1.rhel5" ]]; then 
     rpm -e MySQL-server-5.6.11-2.rhel5 
     rpm -e MySQL-client-5.6.5_m8-1.rhel5 
     echo "MySQL Successfully Removed"; 
elif [ "${arr[0]}" == "MySQL-server-5.6.11-2.rhel5" ]; then 
     rpm -e MySQL-server-5.6.11-2.rhel5 

elif [ "${arr[1]}" == "MySQL-client-5.6.5_m8-1.rhel5" ]; then 
     rpm -e "MySQL-client-5.6.5_m8-1.rhel5 
else 
     echo "Done" 

fi 
+0

从什么时候开始,我们将这些参数的命令直接旁边命令没有任何空格? –

回答

0

您需要在第二个条件添加一个空格:

[["${arr[1]}" == "MySQL-client-5.6.5_m8-1.rhel5"]] 
^          ^
    \          /
    - here        here - 

所以它是

[[ "${arr[1]}" == "MySQL-client-5.6.5_m8-1.rhel5" ]] 
+0

是的它的工作..感谢了很多fedorqui –