2014-09-30 73 views
0
#!/bin/bash 

branch=$1 
vcva=$2 
esx=$3 
pxe=$4 
setup=$5 




#If branch is Vsphere-2015 

if [ "$branch" == "vsphere2015"];then 

     echo " Running Bats for Vsphere-2015 with the following details ." 



if [ ! "vcva" ];then 

    echo "VCVA Build is $2 " 
    echo "ESX Build is $4 " 
    echo "pxe info is $5 " 


#If all the setups has to be run 

setup=$5 
case "$setup" in "all") 

     echo "runnning all setups on Vsphere-2015." 
     vpshere2015_primary 
     vpshere2015_M1N1 
     vpshere2015_M2N1        =======> these are methods 
     vpshere2015_legacy 
    ;; 

我是新來的外殼及這段代碼後得到越來越語法錯誤的情況下,聲明殼

bat.sh:第38行:附近意外的標記newline' 'at.sh: line 38:語法錯誤;;

我想運行取決於在命令行由用戶給定的輸入一些功能

+0

您還需要關閉'之前有空格]' - '[「$ branch」==「vsphere2015」]'應該是'[「$ branch」==「vsphere2015」]''。原因:'['命令要求其最後一個參數必須是']',並且參數之間用空格分隔。 – 2014-09-30 12:17:11

回答

1

case satatement必須esac

case語法END是

case EXPRESSION in CASE1) COMMAND-LIST;; CASE2) COMMAND-LIST;; ... CASEN) COMMAND-LIST;; esac 

所以在這裏應該是

case "$setup" in "all") 

     echo "runnning all setups on Vsphere-2015." 
     vpshere2015_primary 
     vpshere2015_M1N1 
     vpshere2015_M2N1        =======> these are methods 
     vpshere2015_legacy 
    ;; 

esac 

這裏曾經$setupall匹配整個命令列表excecuted

而且,它不限制,你應該把all在報價" "

案「$設置」,在所有)

 echo "runnning all setups on Vsphere-2015." 
     vpshere2015_primary 
     vpshere2015_M1N1 
     vpshere2015_M2N1        =======> these are methods 
     vpshere2015_legacy 
    ;; 

esac 

也沒關係

1

你只需要關閉,如果的(用「網絡」)所有和案例陳述(「esac」)。

我的事情你也必須改變

if [ ! "vcva" ];then 

if [ ! -z "$vcva" ] ; then 

這將導致類似:

#!/bin/bash 

branch=$1 
vcva=$2 
esx=$3 
pxe=$4 
setup=$5 

#If branch is Vsphere-2015 
if [ "$branch" == "vsphere2015" ];then 
    echo " Running Bats for Vsphere-2015 with the following details ." 
    if [ ! -z "$vcva" ];then 
    echo "VCVA Build is $2 " 
    echo "ESX Build is $4 " 
    echo "pxe info is $5 " 

    #If all the setups has to be run 
    setup=$5 
    case "$setup" in 
     "all")  
     echo "runnning all setups on Vsphere-2015." 
     vpshere2015_primary 
     vpshere2015_M1N1 
     vpshere2015_M2N1 
     vpshere2015_legacy 
     ;; 
     *) 
     echo "default action goes here" 
     ;; 
    esac 
    fi # close second if 
fi # close first if