LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Unexpected end of file error when running a shell script (http://www.linuxquestions.org/questions/linux-newbie-8/unexpected-end-of-file-error-when-running-a-shell-script-755000/)

Laughing_Man 09-14-2009 03:32 AM

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!

catkin 09-14-2009 04:44 AM

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!

lutusp 09-14-2009 05:57 AM

Quote:

Originally Posted by Laughing_Man (Post 3681904)
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.

i92guboj 09-14-2009 06:43 AM

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.

Laughing_Man 09-14-2009 05:55 PM

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

lutusp 09-14-2009 06:02 PM

Quote:

Originally Posted by Laughing_Man (Post 3682735)
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.

Laughing_Man 09-14-2009 06:13 PM

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.

Laughing_Man 09-14-2009 06:20 PM

Got it! Missed one of the $.

Thank you!

lutusp 09-14-2009 06:43 PM

Quote:

Originally Posted by Laughing_Man (Post 3682746)
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).


All times are GMT -5. The time now is 03:04 AM.