#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    22
    Rep Power
    0

    Syntax error in shell script while using if condition


    I am writing a simple shell script where it checks the condition using if condition.

    Code:
    if [ $name == "JOHN" ] then  admin='YES'; fi
    if I use like this I am getting below error

    Code:
    syntax error near unexpected token `fi'
    While using as below I have no errors, it is sucessful.

    Code:
    if [ $name == "JOHN" ] 
    then  
    admin='YES'; 
    fi
    Can you please let me know if I am doing some mistake in the first case. I need the first case to work so that I can format it good, since this is the only condition taking 4 lines.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,402
    Rep Power
    1688
    Use either:

    Code:
    if [ $name == "JOHN" ]; then admin="YES"; fi
    or

    Code:
    if [ $name = "JOHN" ]
    then
      admin="YES"
    fi
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo