LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-15-2006, 05:14 PM   #1
anamericanjoe
Member
 
Registered: May 2006
Posts: 69

Rep: Reputation: 16
Trouble with Bash -- syntax error near unexpected token `fi'


This is my first post to LQ, so please be patient with me!

I am getting a strange error from Bash from the following .profile:

Code:
#
# ~/.profile
#
PS1="{\w} "
alias vi=vim

export PATH=$PATH:~/bin

if [ -f ~/.agent.env ]; then
        . ~/.agent.env > /dev/null

        if ! kill -0 $SSH_AGENT_PID > /dev/null 2>&1 then
                echo "Stale agent file found. Spawning new agent..."
                eval `ssh-agent | tee ~/.agent.env`
                ssh-add
        fi
else
        echo "Starting ssh-agent..."
        eval `ssh-agent | tee ~/.agent.env`
        ssh-add
fi
#
# end ~/.profile
#
When I start a shell, Bash complains with

bash: /home/me/.profile: line 16: syntax error near unexpected token `fi'
bash: /home/me/.profile: line 16: ` fi'


I am using GNU bash, version 3.00.16, and the part of my profile starting from the if statement is copied directly from the O'Reilly book Linux Server Hacks (Hack #69).

Does anyone know why Bash is complaining about fi at line 16?

Thanks!
 
Old 05-15-2006, 05:34 PM   #2
ataraxia
Member
 
Registered: Apr 2006
Location: Pittsburgh
Distribution: Debian Sid AMD64
Posts: 296

Rep: Reputation: 30
You don't have a ; before the "then" in your second "if" line.
 
Old 05-15-2006, 05:38 PM   #3
anamericanjoe
Member
 
Registered: May 2006
Posts: 69

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by ataraxia
You don't have a ; before the "then" in your second "if" line.
I changed this:

if ! kill -0 $SSH_AGENT_PID > /dev/null 2>&1 then

to this

if ! kill -0 $SSH_AGENT_PID > /dev/null 2>&1; then

and it worked!

Thank you ataraxia!
 
Old 05-18-2006, 11:11 PM   #4
zwylinux
LQ Newbie
 
Registered: May 2006
Posts: 27

Rep: Reputation: 15
be careful next time,guy
 
Old 05-19-2006, 12:19 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
conventionally, 'then' goes on the next line, therefore no ';' ... like this
if [[ sometest ]]
then
do_something
fi
 
Old 05-19-2006, 02:59 PM   #6
anamericanjoe
Member
 
Registered: May 2006
Posts: 69

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by chrism01
conventionally, 'then' goes on the next line, therefore no ';' ... like this
if [[ sometest ]]
then
do_something
fi
Thanks for the tip!

I am a surprised that this sort of a typo is in an O'Reilly book, but accidents happen I guess...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax error near unexpected token `fi' Warmduvet Programming 21 10-08-2013 10:28 AM
error: unexpected token `newline' CarlosV Programming 4 05-17-2011 03:47 AM
syntax error near unexpected token ` mattyspatty Programming 8 05-07-2006 05:19 PM
Many errors when 'make'ing (example: error: syntax error before `::' token) darkblade Linux - Software 5 03-02-2005 03:00 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM


All times are GMT -5. The time now is 06:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration