0

I get this unexpected 'done' token error

echo -e "Enter the file stem name"
read filestem
for i in {1..22}
do
    `java -cp /export/home/alun/jpsgcs/ CMorgansToTheta $filestem_$i.INPUT.par $filestem_$i.THETA.par`
done
6
  • Have you tried adding the #!/bin/bash header to the top of the script? Commented Jun 18, 2013 at 17:17
  • 5
    Why do you have java -cp .. in backticks? Doesn't make sense, unless you're getting output of the java command to some variable. Commented Jun 18, 2013 at 17:21
  • 2
    or removing the backticks? Does that java program really return executable bash statements? Commented Jun 18, 2013 at 17:23
  • 1
    I just tried it on my system, and didn't get that error. Is that the entire script? If not, please update your question to show us all of it (copy-and-paste, don't re-type). As @depesz says, the backticks don't make sense, but they shouldn't cause the symptom you're seeing,. Commented Jun 18, 2013 at 17:24
  • the -cp is the class path and without those i get classdefnotfound error in java. And that is all the code is and i added #! /bin/bash too. I get the same error. Commented Jun 18, 2013 at 19:16

2 Answers 2

5

If the Java program writes nothing to output, your for loop is equivalent (because of the backquotes) to

for i in {1..22}
do
done

which produces the error you see. It's likely you simply want to remove the backquotes to run the program 22 time:

echo -e "Enter the file stem name"
read filestem
for i in {1..22}
do
    java -cp /export/home/alun/jpsgcs/ CMorgansToTheta "${filestem}_$i.INPUT.par" "${filestem}_$i.THETA.par"
done
Sign up to request clarification or add additional context in comments.

2 Comments

From the shell script or from the Java program? I fixed a small bug in the shell script that would pass the wrong filenames to the Java program.
the unexpected end of file error is from the script. not java program
1

In your Java command line:

java -cp /export/home/alun/jpsgcs/ CMorgansToTheta $filestem_$i.INPUT.par $filestem_$i.THETA.par

You are using:

$filestem_$i

Which will be equivalent to:

${filestem_}${i}

because underscore _ is not considered a word boundary in shell and whole filestem_ will be considered variable name. Most likely you should be using:

${filestem}_${i}

Can you show me output of this script?

#!/bin/bash
set -x
echo -e "Enter the file stem name"
read filestem
for i in {1..3}
do
    echo "java -cp /export/home/alun/jpsgcs/ CMorgansToTheta ${filestem}_${i}.INPUT.par ${filestem}_${i}.THETA.par"
done

12 Comments

Ok can you post your latest suggested script in your question.
echo -e "Enter the file stem name" read filestem for i in {1..22} do java -cp /export/home/alun/jpsgcs/ cMorgansToTheta ${filestem}_${i}.INPUT.par ${filestem}_${i}.THETA.par done
ok looks like you accepted other answer, probably got your problem solved.
That was a misclick. Am sorry about that.
I still get that undefined token done error. There is another weird thing that my "for" is not highlighted in the vi editor. @anubhava
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.