0

I have a script that loops over my files, combine two files and run a python script. However, if I run this, I get a error:

Syntax error: end of file unexpected (expecting "done")

What is wrong with my script?

#!/bin/sh
for file1 in *R1*fastq
do 
    file2=${file1/R1/R2}
    out=${file1%%.fastq}_output
    python spades.py --careful -1 $file1 -2 $file2 -o $out 
done
Gravel
  • 337
  • 4
  • 15
  • Almost certainly your file format has DOS newlines or other hidden characters. That would make the `done` instead be parsed as `$'done\r'`, with a CR at the end, and so a different word. – Charles Duffy Jul 26 '17 at 17:16
  • BTW, there are other bugs here that you'll probably only detect when dealing with unusual filenames. Consider running your code through http://shellcheck.net/ and fixing what it finds. – Charles Duffy Jul 26 '17 at 17:30
  • I did like you suggest and now I have the error "bad substitution" for line 4. Do you know how that is happening? I already tried to run dos2unix before running the script. – Gravel Jul 26 '17 at 17:47
  • That's an unrelated error: `#!/bin/sh` doesn't support `${var/old/new}`. You need a more capable shell -- use `#!/bin/bash`. – Charles Duffy Jul 26 '17 at 17:50

0 Answers0