Find the answer to your Linux question:
Results 1 to 3 of 3
Hello everyone, I'm having problems with a syntax error in an if then statement. The script is designed to allow the user to configure their computer to work with the ...
  1. #1
    Just Joined!
    Join Date
    Sep 2010
    Posts
    8

    [SOLVED] I'm having problems with an if then statement in a bash scrip

    Hello everyone,

    I'm having problems with a syntax error in an if then statement. The script is designed to allow the user to configure their computer to work with the ubuntu-manual project, and I decided to allow the user to choose whether or not to enter their launchpad username into bzr (in honesty, I did this because I don't have the RSA key set up on my test computer, and I don't want to have to do that to make the script work otherwise).

    I'm getting

    ./configure-ubuntu-manual.sh: line 79: syntax error near unexpected token `fi'
    ./configure-ubuntu-manual.sh: line 79: `fi'

    when I execute the script.

    Here is the relevant portion of the script:

    Code:
    echo
    echo "Do you wish to have bzr log you into launchpad?  Note, that it will warn you if we don't configure a login, however you will still be able to download the files." 
    read YAYNAY
    
    if [ $YAYNAY = 'Y' ] then
        echo
        echo "Please enter your launchpad username, in order to have write and other access to the project on the server.  This is mainly because if we don't do this, bzr will put up a warning that states we don't have this access before it downloads the files.  You will NOT be prompted for your password." 
        read USERNAME
    
        bzr launchpad-login $USERNAME
    fi
    
    echo
    echo "Next, we will run bzr branch lp:ubuntu-manual to download our branch:  This may take a few minutes, while bzr downloads the files for the project."
    
    bzr branch lp:ubuntu-manual
    For reference, I've tried if [ $YAYNAY == "Y" ], if [ $YAYNAY = "Y" ], and every other combination of this. The only thing I haven't tried is removing the blank lines inside of the if statement.

    I've even tried an else statement. It's something inside of the "true" portion of the statement, because when I had the else statement, it triggered the error on 'else'.

    I'm at a total loss here, as I've never programmed in bash (at least nothing this complex). I have a feeling it's something simple, like needing {}'s around the true statements, or a ; at the end of the last one. But, I'm lost.

    Thanks for any help with this, and if you need the entire script, I'll be more than happy to post it.

    Have a great day
    Patrick.

  2. #2
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    119
    Your if/then has to either be on different lines, or you need to use a semi-colon.

    Code:
    if [ test ]; then
       echo answer
    fi
    OR
    Code:
    if [ test ]
     then echo answer
    fi

  3. #3
    Just Joined!
    Join Date
    Sep 2010
    Posts
    8
    Quote Originally Posted by markcole View Post
    Your if/then has to either be on different lines, or you need to use a semi-colon.

    Code:
    if [ test ]; then
       echo answer
    fi
    OR
    Code:
    if [ test ]
     then echo answer
    fi
    Thank you. That was the problem. It works (at least it works as well as can be expected). Thanks.

    Have a great day, and Happy Holidays
    Patrick.

Posting Permissions

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