LinuxQuestions.org
Register a domain and help support LQ
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 09-14-2009, 02:32 AM   #1
Laughing_Man
LQ Newbie
 
Registered: Sep 2009
Location: Seattle
Posts: 8

Rep: Reputation: 0
Unexpected end of file error when running a shell script


So I've been working on a shell script and have got all the bugs out, save one. I've combed the forums and tried every trick I could find (od -c filename, throwing in EOF, ending with 'exit' and 'exit(1)' etc), and no dice.

So. I come to you in need.

The script was built in vi, if that's important. On to the code:

#!/bin/bash
make -f makeebm
# Comments in Bash

TransSet="0 1 2 3 4 5 6 7 8 9 10"

function Scientific_Number { echo $(echo $(int:0:1))".e"$(($(echo $int | wc -c)-2)) }

for trans in $TransSet; do
ext=$((10-$trans))
ref=ext
while $ref >= 0; do
$abs=$(($ext-$ref))
int=$abs
abssci=$(Scientific_Number)
int=$trans
transsci=$(Scientific_Number)
int=$ref
refsci=$(Scientific_Number)
Prefix=${transsci}trans_${abssci}abs_${refsci}ref
echo "abs = $abssci">inputfile.dat
echo "trans = $transsci">>inputfile.dat
echo "ref = $refsci">>inputfile.dat
./ebm.exe>&OUTPUTS/${prefix}.log
cp fort.40 OUTPUTS/${prefix}.out
scat=$((scat-1))
done
done

when i try to run it i get:
./ebm.script: line 29: syntax error: unexpected end of file

sometimes it helps to get another pair of eyes on the issue - thanks everyone!
 
Old 09-14-2009, 03:44 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Please post again in code tags with line numbers.

EDIT:

Something, which the shell identifies as started on line 29, was not finished by the end of the script. Maybe an unclosed "do", "if", "{" or "(". Maybe an unclosed '"' or "'" (but I think the error message is more specific for those).

Without knowing which is line 29 (and presuming you have deleted some comment lines so counting is not an option) and not being able to see any indentation to help line up the if-fi, do-done compound commands makes the task of analysis unnecessarily hard!

Last edited by catkin; 09-14-2009 at 03:52 AM.
 
Old 09-14-2009, 04:57 AM   #3
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by Laughing_Man View Post
So I've been working on a shell script and have got all the bugs out, save one. I've combed the forums and tried every trick I could find (od -c filename, throwing in EOF, ending with 'exit' and 'exit(1)' etc), and no dice.

So. I come to you in need.

The script was built in vi, if that's important. On to the code:

#!/bin/bash
make -f makeebm
# Comments in Bash

TransSet="0 1 2 3 4 5 6 7 8 9 10"

function Scientific_Number { echo $(echo $(int:0:1))".e"$(($(echo $int | wc -c)-2)) }

for trans in $TransSet; do
ext=$((10-$trans))
ref=ext
while $ref >= 0; do
$abs=$(($ext-$ref))
int=$abs
abssci=$(Scientific_Number)
int=$trans
transsci=$(Scientific_Number)
int=$ref
refsci=$(Scientific_Number)
Prefix=${transsci}trans_${abssci}abs_${refsci}ref
echo "abs = $abssci">inputfile.dat
echo "trans = $transsci">>inputfile.dat
echo "ref = $refsci">>inputfile.dat
./ebm.exe>&OUTPUTS/${prefix}.log
cp fort.40 OUTPUTS/${prefix}.out
scat=$((scat-1))
done
done

when i try to run it i get:
./ebm.script: line 29: syntax error: unexpected end of file

sometimes it helps to get another pair of eyes on the issue - thanks everyone!
I couldn't initially get the script to run because a number of syntax and coding errors. If you will reformat your script, give it sane indenting and avoid multiple commands per line where practical, this would help comprehension:

Code:
#!/bin/bash
make -f makeebm
# Comments in Bash

TransSet="0 1 2 3 4 5 6 7 8 9 10"

function Scientific_Number {
   echo $(echo ${int:0:1})".e"$(($(echo $int | wc -c)-2))
}

for trans in $TransSet
do
   ext=$((10-trans))
   ref=$ext
   while [ $ref -ge 0 ]
   do
      abs=$(($ext-$ref))
      int=$abs
      abssci=$(Scientific_Number)
      int=$trans
      transsci=$(Scientific_Number)
      int=$ref
      refsci=$(Scientific_Number)
      prefix=${transsci}trans_${abssci}abs_${refsci}ref
      echo "abs = $abssci">inputfile.dat
      echo "trans = $transsci">>inputfile.dat
      echo "ref = $refsci">>inputfile.dat
      ./ebm.exe>&OUTPUTS/${prefix}.log
      cp fort.40 OUTPUTS/${prefix}.out
      scat=$((scat-1))
      ((ref--)) # added this line
   done
done
(I reformatted your script with my free program beautify_bash and fixed a number of errors)

I am not seeing the error message you report, but this version isn't the same script because of all the changes.

Last edited by lutusp; 09-14-2009 at 06:42 AM. Reason: Changed correct variable "Prefix" to "prefix" for consistency with its use later on
 
Old 09-14-2009, 05:43 AM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,040

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
This kind of error is always a symptom of a non-terminated block of any kind. As said above by someone else, an unterminated string (missing quotation mark), code blocks of any kind {} $() $(()), an unterminated if, for or while sentence. That's why the error speaks about an unexpected EOF. EOF is the enf-of-file mark and it's appearing before than expected, because something has not been correctly closed.
 
Old 09-14-2009, 04:55 PM   #5
Laughing_Man
LQ Newbie
 
Registered: Sep 2009
Location: Seattle
Posts: 8

Original Poster
Rep: Reputation: 0
Sorry everyone! Didn't know that just copying and pasting out of X11 would get rid of the indentation (my first post - NOW I know about code tags).

Also, you'll notice the 'comments in bash' line - I have yet to add any comments (I know, I know...) but I'll throw some in if it'd make a difference.

Here it is:

Code:
#!/bin/bash
make -f makeebm
# Comments in Bash

(5) TransSet="0 1 2 3 4 5 6 7 8 9 10"

function Scientific_Number { echo $(echo $(int:0:1))".e"$(($(echo $int | wc -c)-2))}

for trans in $TransSet; do
10      ext=$((10-$trans))
        ref=ext
                while $ref >= 0; do
                       $abs=$(($ext-$ref))
                        int=$abs
15                      abssci=$(Scientific_Number)
                        int=$trans
                        transsci=$(Scientific_Number)
                        int=$ref
                        refsci=$(Scientific_Number)
20                      Prefix=${transsci}trans_${abssci}abs_${refsci}ref
                        echo "abs = $abssci">inputfile.dat
                        echo "trans = $transsci">>inputfile.dat
                        echo "ref = $refsci">>inputfile.dat
                        ./ebm.exe>&OUTPUTS/${prefix}.log
25                      cp fort.40 OUTPUTS/${prefix}.out
                        scat=$((scat-1))
                done
        done
so there isn't a line 29...
 
Old 09-14-2009, 05:02 PM   #6
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by Laughing_Man View Post
Sorry everyone! Didn't know that just copying and pasting out of X11 would get rid of the indentation (my first post - NOW I know about code tags).

Also, you'll notice the 'comments in bash' line - I have yet to add any comments (I know, I know...) but I'll throw some in if it'd make a difference.

Here it is:

Code:
#!/bin/bash
make -f makeebm
# Comments in Bash

(5) TransSet="0 1 2 3 4 5 6 7 8 9 10"

function Scientific_Number { echo $(echo $(int:0:1))".e"$(($(echo $int | wc -c)-2))}

for trans in $TransSet; do
10      ext=$((10-$trans))
        ref=ext
                while $ref >= 0; do
                       $abs=$(($ext-$ref))
                        int=$abs
15                      abssci=$(Scientific_Number)
                        int=$trans
                        transsci=$(Scientific_Number)
                        int=$ref
                        refsci=$(Scientific_Number)
20                      Prefix=${transsci}trans_${abssci}abs_${refsci}ref
                        echo "abs = $abssci">inputfile.dat
                        echo "trans = $transsci">>inputfile.dat
                        echo "ref = $refsci">>inputfile.dat
                        ./ebm.exe>&OUTPUTS/${prefix}.log
25                      cp fort.40 OUTPUTS/${prefix}.out
                        scat=$((scat-1))
                done
        done
so there isn't a line 29...
Please read my post above in this thread -- I solved your problem by rewriting the script.
 
Old 09-14-2009, 05:13 PM   #7
Laughing_Man
LQ Newbie
 
Registered: Sep 2009
Location: Seattle
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks for your help Lutusp - I changed the code to match yours and it solved the EOF problem, but every time the do loop goes through another iteration I get an error:

Code:
./ebm.script: line 17: =0: command not found
./ebm.script: line 17: =1: command not found
./ebm.script: line 17: =2: command not found
./ebm.script: line 17: =3: command not found
./ebm.script: line 17: =4: command not found
./ebm.script: line 17: =5: command not found
./ebm.script: line 17: =0: command not found
...and so on. So it looks like something in the loop isn't doing its job.
 
Old 09-14-2009, 05:20 PM   #8
Laughing_Man
LQ Newbie
 
Registered: Sep 2009
Location: Seattle
Posts: 8

Original Poster
Rep: Reputation: 0
Got it! Missed one of the $.

Thank you!
 
Old 09-14-2009, 05:43 PM   #9
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by Laughing_Man View Post
Thanks for your help Lutusp - I changed the code to match yours and it solved the EOF problem, but every time the do loop goes through another iteration I get an error:

Code:
./ebm.script: line 17: =0: command not found
./ebm.script: line 17: =1: command not found
./ebm.script: line 17: =2: command not found
./ebm.script: line 17: =3: command not found
./ebm.script: line 17: =4: command not found
./ebm.script: line 17: =5: command not found
./ebm.script: line 17: =0: command not found
...and so on. So it looks like something in the loop isn't doing its job.
I see by a later post that you found and fixed a copying error, but:

Quote:
I changed the code to match yours
Why didn't you just copy the entire script from your browser display and paste it into your editor? I will readily admit to being too lazy to hand-retype an entire several-hundred word script when copy and paste features exist. This has been true of me since it was first possible to transfer a block of text from one place to another. That's been a long time -- indeed, since Apple Writer in 1981 (which I wrote).
 
  


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
Bash script -----------syntax error: unexpected end of file ArthurHuang Programming 2 05-01-2009 10:29 AM
Sntax error : unexpected end of file while executing shell script priyankarathi Linux - Newbie 5 04-21-2009 01:33 AM
Bash script - syntax error: unexpected end of file Mr Pink Programming 7 12-19-2008 06:31 AM
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 09:28 AM
bash "unexpected end of file" script error Runge_Kutta Linux - General 6 05-23-2007 03:36 PM


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