Results 1 to 8 of 8

Thread: [SOLVED] BASH some errors in my script...

  1. #1
    Join Date
    Jun 2006
    Location
    Georgia
    Beans
    1,072

    [SOLVED] BASH some errors in my script...

    I don't know what I'm doing wrong. I am new to writing bash scripts. Anyone care to help?
    I'm getting this error
    ./facebook: line 45: syntax error: unexpected end of file
    [CODE#]!/bin/bash
    #Installs fbcmd to /usr/lib/fbcmd

    #Get dependencies
    aptitude install php5-cli

    #make new directory for installation
    mkdir /usr/lib/fbcmd

    #Get fbcmd
    wget http://www.cs.ubc.ca/~davet/fbcmd/fbcmd-0-90.tgz /usr/lib/fbcmd

    #extract
    tar -xvf /usr/lib/fbcmd

    #Get AUTH code
    firefox http://www.facebook.com/code_gen.php?v=1.0&api_key=d96ea311638cf65f04b33c8 7eacf371e

    #Ask for AUTH code
    echo -n "What is your AUTH code?"
    read ANSWER

    #Enters AUTH code
    php /usr/lib/fbcmd.php $ANSWER

    #Asks for user name
    echo - "What is your user name on this Linux computer?"
    read NAME

    #Check .bash_aliases existence
    echo - "Do you have a .bash_aliases file in your home directory?(y/n)"
    read BASH
    if [["$BASH"=="n*"]]
    then touch /home/$NAME/.bash_aliases.file
    if [["$BASH"=="y*"]]
    echo "yay"

    #Sets "facebook" alias
    echo "alias facebook='php /usr/lib/fbcmd.php'" >> /home/$NAME/.bash_aliases

    #Finished
    exit #
    [/code]
    Acer Aspire 3680, Intel Celeron M, 1.41 GB RAM
    Feel free to message me if you have any questions.

  2. #2
    Join Date
    Nov 2008
    Location
    Lleida, Spain
    Beans
    1,157
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: BASH some errors in my script...

    In your code
    You do
    if ["a"=="b"]
    and you should do
    if [ "a" == "b" ]

  3. #3
    Join Date
    Jun 2006
    Location
    Georgia
    Beans
    1,072

    Re: BASH some errors in my script...

    Quote Originally Posted by albandy View Post
    In your code
    You do
    if ["a"=="b"]
    and you should do
    if [ "a" == "b" ]
    okay. Now I'm getting a
    ./facebook: line 43: syntax error: unexpected end of file
    Acer Aspire 3680, Intel Celeron M, 1.41 GB RAM
    Feel free to message me if you have any questions.

  4. #4
    Join Date
    Jun 2006
    Location
    Georgia
    Beans
    1,072

    Re: BASH some errors in my script...

    Quote Originally Posted by albandy View Post
    In your code
    You do
    if ["a"=="b"]
    and you should do
    if [ "a" == "b" ]
    Thanks, Now I'm getting
    Code:
    ./facebook: line 43: syntax error: unexpected end of file
    any ideas?
    Acer Aspire 3680, Intel Celeron M, 1.41 GB RAM
    Feel free to message me if you have any questions.

  5. #5
    Join Date
    Nov 2008
    Location
    Lleida, Spain
    Beans
    1,157
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: BASH some errors in my script...

    the if statements ends with fi

    if [ "a" == "b" ]
    then
    a command
    fi

  6. #6
    Join Date
    Jun 2006
    Location
    Georgia
    Beans
    1,072

    Re: [SOLVED] BASH some errors in my script...

    Just started working on this again.

    There's one part
    Code:
    #Check .bash_aliases existence
    echo - "Do you have a .bash_aliases file in your home directory?(y/n)" 
    read BASH
    if [ $BASH == "n"]
    then 
        touch /home/$NAME/.bash_aliases.file
    fi
    It gives me
    Code:
    [: 40: missing ]
    I know it' something small. Any help is great.
    Acer Aspire 3680, Intel Celeron M, 1.41 GB RAM
    Feel free to message me if you have any questions.

  7. #7
    Join Date
    Apr 2005
    Location
    Warsaw, Poland
    Beans
    111
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: BASH some errors in my script...

    Add a space between "n" and ]. And change "==" to "=".

  8. #8
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: BASH some errors in my script...

    Quote Originally Posted by odyniec View Post
    And change "==" to "=".
    Using a single = is more standard, and it's required if you're running in sh. But Bash allows either = or ==.
    Quote Originally Posted by tdrusk View Post
    Code:
    #Check .bash_aliases existence
    echo - "Do you have a .bash_aliases file in your home directory?(y/n)" 
    read BASH
    if [ $BASH == "n"]
    then 
        touch /home/$NAME/.bash_aliases.file
    fi
    Why are you asking the user if a file exists? The user might not know, or they might give a wrong answer. Just do a simple test:
    Code:
    if [[ -f $HOME/.bash_aliases ]]; then   # type man test for a list of other good stuff you can test for
      echo "Yay! It's there!"
    else
      echo "Why don't you have it?"
    fi
    Also, $NAME isn't a standard environment variable. Did you mean $USER? Or better yet, use $HOME, because home directories can be anywhere (root's is at /root, not /home/root). Use the env command to see a list of the currently-defined environment variables (some of which might not always be defined).

Bookmarks

Posting Permissions

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