LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-04-2010, 02:09 PM   #1
SilversleevesX
Member
 
Registered: May 2009
Posts: 181
Blog Entries: 9

Rep: Reputation: 15
Unexpected end-of-file error (bash script) - need another pair of eyes.


I'm pretty much satisfied that all the i's have been dotted and the t's crossed, so far as if/fi, closed parentheses, in-out quotation marks and the like go. I just need another pair of eyes to be sure. My bash shell keeps insisting on there being a line 32 to this script, while nano, vim and the "cat foo.sh | wc -l" combo all agree with my GUI text editor (with which I wrote 98% of the script -- and yes it's been dos2unix'ed as well)-- there are only 31 lines!

Here's the script:

Code:
#!/bin/bash -x
echo -ne "Fixture Identification Fixer for Exiv2 - FIFE\n"
echo -ne "Please enter the name of the file you want to modify.\n"
read gfile
if [ -e $gfile ]
then
	oldf1=$(exiv2 -PInv $gfile | grep 'FixtureId' | sed 's/^FixtureId[       ]*//')
	echo -e "The word or phrase currently in this file reads: ${oldf1}.\n"
	echo -ne "Do you want to change this Fixture ID to something else?  y/n \n"
	read yesorno
	if [ $yesorno = "n" ] 
	then
		echo -ne "No changes made to file ${gfile}\.\n"
	else
		echo "Are you sure? y/n "
		read confirmm
		if [ $confirmm = "n" ]
		then
			exit 1;
		else
			exiv2 -M"del Iptc.Application2.FixtureId" modify $gfile
			echo -e "The old FixtureID has been removed."
			echo -ne "Please enter the word or phrase to replace '$oldfi .'\n"
			read newstringhx
			exiv2 -M"add Iptc.Application2.FixtureId String $newstringhx" modify $gfile
		sleep 1
			echo -ne "The new phrase, \"$newstringhx\",\n has been written to file \033[37;40m${gfile}.\033[0m\n"
		fi
	fi
else
	echo -e "Sorry, that file is not in this folder."
You might notice one if without an fi. Everytime I add it back, I get an "unexpected token" error for it and its line. So there's got to be some other punctuation or complementary code missing somewhere.

Hope someone finds whatever it is, and can point it out to me. No sweat off my knee if it was something I couldn't see (rhyme unintended).

BZT
 
Old 02-04-2010, 02:26 PM   #2
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
If I add an "fi" at the end, the script runs without errors.

But you should replaces

Code:
if [ $yesorno = "n" ]
with
Code:
if [ "X$yesorno" == "Xn" ]
to avoid a problem, if yesorno is empty.
 
1 members found this post helpful.
Old 02-04-2010, 06:11 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,434

Rep: Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790
Use [[ ]] to deal with that http://www.tldp.org/LDP/abs/html/tes...ml#DBLBRACKETS
 
1 members found this post helpful.
Old 02-05-2010, 12:04 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by irmin View Post
But you should replaces

Code:
if [ $yesorno = "n" ]
with
Code:
if [ "X$yesorno" == "Xn" ]
to avoid a problem, if yesorno is empty.
More elegantly the problem can be solved like this (the double quotes around n were not wrong but single quotes are adequate)
Code:
if [ "$yesorno" = 'n' ]
But chrism01 is right to point out that [[ ]] is a better solution. [[ ]] is preferred over [ ] for reasons explained here.
 
Old 02-05-2010, 12:07 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
This thread is a duplicate of this thread.
 
Old 02-05-2010, 09:34 AM   #6
SilversleevesX
Member
 
Registered: May 2009
Posts: 181

Original Poster
Blog Entries: 9

Rep: Reputation: 15
To avoid another duplication...

@chrism,

I thought that approach, double-brackets, would be the way to go about it, too. I've found that they do prevent errors of a few types in other scripts. Good to have a reminder.

Quote:
Originally Posted by chrism01 View Post
@catkin:

I apologize for the duplicate thread. I'm not certain as to how it occurred, but I suspect it may have been due to a double-login on my part, ie, closing a window with the site (and the original thread) in it and not waiting for the customary timeout before logging back in while viewing another thread (which link opened via Google or some item in my browser history). I'll do what I can to add only to this thread, unless doing so makes deleting its twin more difficult. I'd appreciate your advice on how to proceed.


Quote:
Originally Posted by catkin
This thread is a duplicate of this thread.

BZT
 
Old 02-05-2010, 09:41 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by SilversleevesX View Post
I apologize for the duplicate thread. I'd appreciate your advice on how to proceed.
No worries

You could use the Report button on the first post in one of the threads to ask the moderators to close it.
 
Old 02-05-2010, 02:12 PM   #8
SilversleevesX
Member
 
Registered: May 2009
Posts: 181

Original Poster
Blog Entries: 9

Rep: Reputation: 15
Done.

Quote:
Originally Posted by catkin View Post
No worries

You could use the Report button on the first post in one of the threads to ask the moderators to close it.
Done.

BZT
 
  


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
Unexpected end-of-file error (bash script) - need another pair of eyes. SilversleevesX Linux - Newbie 10 02-05-2010 02:21 PM
bash line 74: syntax error: unexpected end of file help? andycol Linux - General 5 09-14-2009 08:12 AM
Bash script -----------syntax error: unexpected end of file ArthurHuang Programming 2 05-01-2009 10:29 AM
Bash script - syntax error: unexpected end of file Mr Pink Programming 7 12-19-2008 06:31 AM
bash "unexpected end of file" script error Runge_Kutta Linux - General 6 05-23-2007 03:36 PM

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

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