LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Unexpected end-of-file error (bash script) - need another pair of eyes. (http://www.linuxquestions.org/questions/linux-newbie-8/unexpected-end-of-file-error-bash-script-need-another-pair-of-eyes-787061/)

SilversleevesX 02-04-2010 02:05 PM

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."

Hope someone finds something. No sweat off my knee if it was something I couldn't see (rhyme unintended).

BZT

allanf 02-04-2010 02:12 PM

Quote:

Originally Posted by SilversleevesX (Post 3852908)
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."

Hope someone finds something. No sweat off my knee if it was something I couldn't see (rhyme unintended).

BZT

Your if is not closed needs a final:
fi

rweaver 02-04-2010 02:12 PM

add:
Code:

fi
as your 32nd line of the script.

GrapefruiTgirl 02-04-2010 02:12 PM

You're missing a "fi" as the very last line of the file :)

GrapefruiTgirl 02-04-2010 02:14 PM

Hmm, seems we all posted at once :D -- based on commonalities between the replies, it looks like a missing "fi" is the problem.

neonsignal 02-04-2010 02:15 PM

Missing 'fi' at the end.

==EDIT==
redundant :-)

SaintDanBert 02-04-2010 02:56 PM

You might get this error when your absolutely final record in the script file ends with
Code:

blah blah blah end-of-file
instead of
Code:

blah blah blah newline
end-of-file

Hmmm, should I have used the od --format=x1c command to show this?

~~~ 0;-Dan

rweaver 02-04-2010 03:37 PM

Quote:

Originally Posted by GrapefruiTgirl (Post 3852922)
Hmm, seems we all posted at once :D -- based on commonalities between the replies, it looks like a missing "fi" is the problem.

There could be other problems but first cure the obvious :)

GrapefruiTgirl 02-04-2010 05:16 PM

Yes, like I would be adding some quotes around the "$variables" inside the test cases.

SilversleevesX 02-05-2010 02:07 PM

More progress has been made on this thread.

Admins: as OP I request the thread this message appears in be deleted asap.

BZT

pixellany 02-05-2010 02:21 PM

Duplicate closed---see link above


All times are GMT -5. The time now is 12:05 AM.