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
    ;;

I'm new to shell and after this piece of code getting

bat.sh: line 38: syntax error near unexpected token newline' 'at.sh: line 38: ;;

I want to run some functions depending upon the inputs given by the user in command line

1
  • You also need a space before the closing ] -- [ "$branch" == "vsphere2015"] should be [ "$branch" == "vsphere2015" ]. The reason: the [ command demands its last argument must be ], and arguments are separated by whitespace. Commented Sep 30, 2014 at 12:17

2 Answers 2

1

The case satatement must end with esac

Syntax of case is

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

So here it should be

case "$setup" in "all")

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

esac

here once $setup is matched with all the entire command list is excecuted

Also, it is not restricted that you should place all in quote " "

case "$setup" in all)

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

esac

will also work fine

Sign up to request clarification or add additional context in comments.

Comments

1

You just have to close all the if's (with "fi") and the case statement (with "esac").

I thing you also have to change the

if [ ! "vcva" ];then

into

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

It will result something like:

#!/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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.