LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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
 
LinkBack 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
Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,850

Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
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,417
Blog Entries: 1

Rep: Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951
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
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware-14.0 on a Lenovo T61 6457-4XG
Posts: 3,672

Rep: Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828
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
Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,850

Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
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


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


All times are GMT -5. The time now is 03:21 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