Find the answer to your Linux question:
Results 1 to 4 of 4
Hi , Caan any one plz helpp me in this...' i got a script like this #!/bin/sh sch = 0 echo "enter echo "1.Usch.sh" echo "2.Ssp.sh" echo "3.uscr_final" echo "4.fttp" ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3

    need help in shell scripting

    Hi ,

    Caan any one plz helpp me in this...'

    i got a script like this

    #!/bin/sh
    sch = 0

    echo "enter
    echo "1.Usch.sh"
    echo "2.Ssp.sh"
    echo "3.uscr_final"
    echo "4.fttp"

    read sch


    if [$sch -eq 1] ; then
    ./Usch.sh
    else if [$sch -eq 2]; then
    ./Scp.sh
    else if [$sch -eq 3]; then
    ./uscr_final.sh
    else if [$sch -eq 4]; then
    ./fttp.sh
    fi

    while i am trying to execute this one it is giving the error like


    else is not matched at he last else statement..


    thanks in advance..

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    I assume every if needs to have a fi.
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3
    adding fi to every if is also not working

  4. #4
    Just Joined! mehorter's Avatar
    Join Date
    May 2006
    Posts
    20
    couple of things..

    first you need the closing quotes on the first echo statement.

    Code:
    echo "enter"
    your test statements need a space around them.

    Code:
    [ $sch -eq 1 ]
    change else if to elif

    Code:
    elif [$sch -eq 2]; then
    I may be wrong but I think the construct will also need a final "else" statement

    Code:
    else echo "Invalid choice"
    You should look in to the case construct
    Bash by example, Part 2
    Using case statements

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...