-1

Writing a custom Shell Script for a college assignment. Have practically everything working apart from this.... I have an alias called ifc which will call a function called functionIfc. However, when this code is used, it tells me that unexpected token '}' is found. Cannot seem to be able to debug this. Been stuck on it for a while. Any help would be greatly appreciated!

  alias ifc="functionIfc";

  functionIfc(){

         echo  "Please enter which ethernet you would like to display"
         echo -e "\n Command ifc1: Shows loopback"
         echo -e "\n Command ifc2: Shows eth 0"
         echo -e "\n Command ifc3  Shows eth 1"
         echo -e "\n Command ifc4 shows eth 2"
         echo -e "\n Command ifc5 shows eth 3"

    read INPUT

    if [ $(INPUT) == "ifc1" ]; then
            echo $(ip addr show lo)

            else if [ $(INPUT) == "ifc2" ]; then
                   echo $(ip addr show eth0)


                    else if [ $(INPUT) == "ifc3" ]; then
                          echo  $(ip addr show eth1)

                            else  if [ $(INPUT) == "ifc4" ]; then
                                 echo $(ip addr show eth2)

                                    else if [ $(INPUT) == "ifc5" ]; then
                                            echo $(ip addr show eth3)

                                            else
                                                    echo Not a valid entry, Try again

    fi
}
Mustafa DOGRU
  • 3,994
  • 1
  • 16
  • 24
Micheal_S
  • 13
  • 1
  • 3
  • Bash functions are declared with () ? Maybe use spaces between and after () ... – Ko2r Oct 21 '16 at 10:14
  • Consider pasting the code in http://www.shellcheck.net/ for grammar check. [Here](http://stackoverflow.com/a/6212408/1983854) you can see the two ways to define functions, @Ko2r – fedorqui Oct 21 '16 at 10:23

1 Answers1

0

you should close each if statement with fi as below;

#!/bin/bash 
  functionIfc(){
         echo  "Please enter which ethernet you would like to display"
         echo -e "\n Command ifc1: Shows loopback"
         echo -e "\n Command ifc2: Shows eth 0"
         echo -e "\n Command ifc3  Shows eth 1"
         echo -e "\n Command ifc4 shows eth 2"
         echo -e "\n Command ifc5 shows eth 3"

    read INPUT


    if [ ${INPUT} == "ifc1" ]; then
            echo $(ip addr show lo)

            else if [ ${INPUT} == "ifc2" ]; then
                   echo $(ip addr show eth0)


                    else if [ ${INPUT} == "ifc3" ]; then
                          echo  $(ip addr show eth1)

                            else  if [ ${INPUT} == "ifc4" ]; then
                                 echo $(ip addr show eth2)

                                    else if [ ${INPUT} == "ifc5" ]; then
                                            echo $(ip addr show eth3)

                                            else
                                                    echo Not a valid entry, Try again
                    fi
                fi
            fi
        fi

    fi
}

functionIfc

and

you can define an alias as below;

alias ifc="/yourscriptpath/"

and you can use this alias in same terminal.

Eg;

user@host $ alias ifc="/tmp/test/t/test.sh"
user@host $ ifc
Please enter which ethernet you would like to display

 Command ifc1: Shows loopback

 Command ifc2: Shows eth 0

 Command ifc3  Shows eth 1

 Command ifc4 shows eth 2

 Command ifc5 shows eth 3
ifc2
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> ...
Mustafa DOGRU
  • 3,994
  • 1
  • 16
  • 24