LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-27-2009, 09:47 AM   #1
Nortekman
LQ Newbie
 
Registered: Oct 2008
Posts: 9

Rep: Reputation: 0
Syntax error near unexpected token fi


Hello everyone, I am having trouble executing a script

When I try to, I get this: Line 31: Syntax error near unexpected token fi and Line 31: fi



if test $# = 0
then
echo
echo This script requires 1 argument
exit
fi

declare -i fileCount
declare -i dirCount
declare -i exeCount

fileCount=0
dirCount=0
exeCount=0

for i in $*
do
if test -f $1
then
fileCount=fileCount+1
fi
if test -d $1
then
dirCount=dirCount+1
fi
if test -x $1
then
exeCount=exeCount+1
fi
done
fi

echo Number of Files found=$fileCount
echo Number of Directories found=$dirCount
echo Number of Executable Files found=$exeCount

Last edited by Nortekman; 02-27-2009 at 09:49 AM.
 
Old 02-27-2009, 09:54 AM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
Looks like you have an extra "fi" after "done".
 
Old 02-27-2009, 09:55 AM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
You don't need the last 'fi'

Why don't you do it like that:

Code:
if test....
   .....
elif test ...
   ...
elif ...
   ...
elif ...
   ...
fi
 
Old 02-27-2009, 09:56 AM   #4
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,058

Rep: Reputation: Disabled
Your last 'fi' does not match an 'if'.

next time please use the [ CODE ] [ /CODE ] tokens and indent your code, it will be easier to read.

Last edited by Didier Spaier; 02-27-2009 at 09:57 AM.
 
Old 02-27-2009, 09:56 AM   #5
Nortekman
LQ Newbie
 
Registered: Oct 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MS3FGX View Post
Looks like you have an extra "fi" after "done".
I deleted it and it still gave the error message
 
Old 02-27-2009, 10:09 AM   #6
Nortekman
LQ Newbie
 
Registered: Oct 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Ok here it goes again:

Code:
 if test $# = 0
then
	echo
	echo This script requires 1 argument
	exit
fi

declare -i fileCount
declare -i dirCount
declare -i exeCount

	fileCount=0
	dirCount=0
	exeCount=0

for i in $*
do
        if test -f $1
	then
		fileCount=fileCount+1
	fi
	if test -d $1
	then
		dirCount=dirCount+1
	fi
	if test -x $1
	then 
		exeCount=exeCount+1
	fi
done
echo Number of Files found=$fileCount
echo Number of Directories found=$dirCount
echo Number of Executable Files found=$exeCount
I still get the same error message
 
Old 02-27-2009, 11:50 AM   #7
rizwanrafique
Member
 
Registered: Jul 2006
Distribution: Debian, Ubuntu, openSUSE, CentOS
Posts: 147

Rep: Reputation: 19
This shouldn't give any error and it doesn't for me.

You're missing some token that you haven't posted online.
 
Old 02-27-2009, 02:26 PM   #8
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
Are you sure you are editing the same script that you are running? The posted script doesn't give any error on my system either.
 
Old 02-27-2009, 03:48 PM   #9
Nortekman
LQ Newbie
 
Registered: Oct 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks everyone, it finally worked. I was editing the backup file, not the original one. The original one still had that extra 'fi'.
 
  


Reply



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 Aigarzs Linux - Newbie 3 01-12-2008 03:39 PM
syntax error near unexpected token deskjockey39 Linux - General 2 01-16-2007 08:47 AM
syntax error for unexpected token `(' Steve Spurr Linux - Newbie 6 09-22-2006 08:19 AM
syntax error near unexpected token `else' josedias Programming 3 09-11-2006 07:09 PM
syntax error near unexpected token ` mattyspatty Programming 8 05-07-2006 05:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:21 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration