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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-27-2009, 09:47 AM
|
#1
|
|
LQ Newbie
Registered: Oct 2008
Posts: 9
Rep:
|
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.
|
|
|
|
02-27-2009, 09:54 AM
|
#2
|
|
Guru
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,817
|
Looks like you have an extra "fi" after "done".
|
|
|
|
02-27-2009, 09:55 AM
|
#3
|
|
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,089
|
You don't need the last 'fi'
Why don't you do it like that:
Code:
if test....
.....
elif test ...
...
elif ...
...
elif ...
...
fi
|
|
|
|
02-27-2009, 09:56 AM
|
#4
|
|
Senior Member
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware-14.0 on a Lenovo T61 6457-4XG
Posts: 2,788
|
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.
|
|
|
|
02-27-2009, 09:56 AM
|
#5
|
|
LQ Newbie
Registered: Oct 2008
Posts: 9
Original Poster
Rep:
|
Quote:
Originally Posted by MS3FGX
Looks like you have an extra "fi" after "done".
|
I deleted it and it still gave the error message
|
|
|
|
02-27-2009, 10:09 AM
|
#6
|
|
LQ Newbie
Registered: Oct 2008
Posts: 9
Original Poster
Rep:
|
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
|
|
|
|
02-27-2009, 11:50 AM
|
#7
|
|
Member
Registered: Jul 2006
Distribution: Debian, Ubuntu, openSUSE, CentOS
Posts: 147
Rep:
|
This shouldn't give any error and it doesn't for me.
You're missing some token that you haven't posted online.
|
|
|
|
02-27-2009, 02:26 PM
|
#8
|
|
Guru
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,817
|
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.
|
|
|
|
02-27-2009, 03:48 PM
|
#9
|
|
LQ Newbie
Registered: Oct 2008
Posts: 9
Original Poster
Rep:
|
Thanks everyone, it finally worked. I was editing the backup file, not the original one. The original one still had that extra 'fi'.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:42 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|