This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error in code

Can anyone please help me with this code? It gives me below error in linux shell

EDIT: Added full code

./HapView_LDBlock.sh: line 27: syntax error: unexpected end of file
#--------------------------------------------------------------------
#Copyright (c) <2006>, <Chun Zhang and Affymetrix INC.>
#All rights reserved.
#This is OSI certified open source software and is distributed 
#under the BSD license.For details please refer to license.txt. 
#------------------------------------------------------
#This script is written by Dr. Chun Zhang
#For calculating LD using 4GAM test
#------------------------------------------------------
count=0
chrnum=14
haphead="HapView_Chr"
hapinfo=".info"
happed=".ped"
while [ $count -lt $chrnum ]
do
    count=`expr $count + 1`
    subcount=0
    tmpped=$haphead$count$happed
    tmpinfo=$haphead$count$hapinfo
    echo $tmpped
    echo $tmpinfo
    if [ -e $tmpped ] 
    then
            java -jar Haploview.jar -nogui -pedfile $tmpped -info $tmpinfo -dprime -blockoutput GAM 
    fi
    done

Thank you in advance!

bash software-error genome

Your code only contains 18~20 lines. So maybe this is not the full file?

I didn't include all of the comments lines, so...Here is the complete code that was in the file

#--------------------------------------------------------------------

#Copyright (c) <2006>, <Chun Zhang and Affymetrix INC.>
#All rights reserved.
#This is OSI certified open source software and is distributed 
#under the BSD license.For details please refer to license.txt. 
#------------------------------------------------------
#This script is written by Dr. Chun Zhang
#For calculating LD using 4GAM test
#------------------------------------------------------
count=0
chrnum=14
haphead="HapView_Chr"
hapinfo=".info"
happed=".ped"
while [ $count -lt $chrnum ]
do
    count=`expr $count + 1`
    subcount=0
    tmpped=$haphead$count$happed
    tmpinfo=$haphead$count$hapinfo
    echo $tmpped
    echo $tmpinfo
    if [ -e $tmpped ] 
    then
            java -jar Haploview.jar -nogui -pedfile $tmpped -info $tmpinfo -dprime -blockoutput GAM 
    fi
    done

Thank you!

3 answers

It seems to me the problem is the ^M (CTRL-M) character at the end of each line. This script was probably written in a text editor in Windows OS and you are trying to run it in Linux. Try to remove those ^M characters and run the script. There are several ways to remove the ^M character.

Hi. Can you helping me in removing ^M? I don't see that letters when I open code in jEdit.

The easiest way is to use "dos2unix" command

dos2unix HapView_LDBlock.sh

Check again to make sure they are gone

cat -v HapView_LDBlock.sh

I did it using "sed" command. It worked.....

Great. Thanks to Ram for suggesting to display the non-printing characters in the file (cat -te).

Could you give us the output of cat -te ./HapView_LDBlock.sh please?

pinku@ram:~/Documents$ ./HapView_LDBlock.sh 
./HapView_LDBlock.sh: line 31: syntax error: unexpected end of file
pinku@ram:~/Documents$ cat -te ./HapView_LDBlock.sh
#--------------------------------------------------------------------^M$
#Copyright (c) <2006>, <Chun Zhang and Affymetrix INC.>^M$
#All rights reserved.^M$
#This is OSI certified open source software and is distributed ^M$
#under the BSD license.For details please refer to license.txt. ^M$
#------------------------------------------------------^M$
#This script is written by Dr. Chun Zhang^M$
#For calculating LD using 4GAM test^M$
#------------------------------------------------------^M$
count=0^M$
chrnum=14^M$
haphead="HapView_Chr"^M$
hapinfo=".info"^M$
happed=".ped"^M$
while [ $count -lt $chrnum ]^M$
do^M$
^Icount=`expr $count + 1`^M$
^Isubcount=0^M$
^Itmpped=$haphead$count$happed^M$
^Itmpinfo=$haphead$count$hapinfo^M$
^Iecho $tmpped^M$
^Iecho $tmpinfo^M$
^Iif [ -e $tmpped ] ^M$
^Ithen^M$
^I^I    java -jar Haploview.jar -nogui -pedfile $tmpped -info $tmpinfo -dprime -blockoutput GAM ^M$
^Ifi^M$
^Idone^M$

Thank you so much for helping me out on this!

^Iif [ -e $tmpped ] ^M$
^Ithen^M$
^I^I    java -jar Haploview.jar -nogui -pedfile $tmpped -info $tmpinfo -dprime -blockoutput GAM ^M$
^Ifi^M$
^Ithen^M$
^Idone^M$

You seem to have a then in the line before your done. Try removing that.

I didn't work again!

Quick question: Why does the code you pasted for Sam here not correspond to the cat -te output or the code pasted in the question? Please double check your code and give us the exact code you are using.

Also, before the cat -te, your execution points to an error in a non-existent line 31. I'd appreciate it if you could share the file directly with us, using DropBox or some such service. Or let me know if you'd be more comfortable emailing the file to me.

Debug error: There is no 27th line in the given code.

I don't see lines after "done" in the code file, however, the shell expecting 'then' after 'done' and I'm not sure what to be included in there....

Log in to answer this question.