Shell脚本for循环错误:语法错误:word意外(期待“do”)

时间:2017-06-16 13:32:05

标签: shell

所以我意识到其他人过去曾问过类似的问题,但是当我尝试他们的解决方案时(使用dos2unix,并检查vim是否有无关的符号),它们根本不起作用。

#!/bin/bash
#-----------------------------------------------------------------------------
mainDir=/mnt/data1/sam
#-----------------------------------------------------------------------------
----------------------------------------------------------------------------
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
cd $fastqDir
for i in `ls *R1_001.fastq.gz`
do
#----------------------------------
 filename="${i%_R1_001.fastq.gz}"
#---------------------------------- 
    #adapter-trim
#---------------------------------- 
 echo "Alignment started for $filename" >> ${qcDir}/${filename}_report.txt

 filename="${i%_R1_001.fastq.gz}"
 echo $filename

 echo "Alignment started for $filename" >> ${qcDir}/${filename}_report.txt
 sed '/chrM/d;/chrY/d;/random/d;/chrUn/d' < Aligned.out.sam | samtools view -bS -F 4 -q 30 -u - | samtools sort - > ${bamDir}/${filename}.bam 
 rm Aligned.out.sam
 mv Log.final.out ${qcDir}/${filename}_STARLogFinal.txt 

 echo "Picard started for $filename" >> ${qcDir}/${filename}_report.txt
 mv ${bamDir}/${filename}_dedup.bam ${bamDir}/${filename}.bam 
 samtools index ${bamDir}/${filename}.bam 

 echo "Picard insert size histogram for $filename" >> ${qcDir}/${filename}_report.txt
 INSERT_TXT_FILE="${qcDir}/${filename}.insertSizes.txt"
 INSERT_HISTO_FILE="${qcDir}/${filename}.insertSizes.pdf"

 echo "Making bigwig for $filename"
    lines=$(samtools view -c ${bamDir}/${filename}.bam);\
    bedtools genomecov -ibam ${bamDir}/${filename}.bam -bg -scale $(echo "1000000 / ${lines} " | bc -l) -g ${RefDir}/${genome}.chrom.sizes | \
    wigToBigWig -clip stdin ${RefDir}/${genome}.chrom.sizes ${bwDir}/${filename}.bw 2> $tmpDir/${filename}_log

 echo "macs2 for $filename"
done

我一直收到错误

Syntax error: word unexpected (expecting "do")

很抱歉,如果这个问题有点愚蠢,我完全不熟悉shell脚本。

1 个答案:

答案 0 :(得分:0)

毕竟,事实证明这是无关紧要的人物。我运行了以下命令,然后脚本开始工作。对不起,感谢大家的帮助!

tr -cd '\11\12\15\40-\176' < file-with-binary-chars > clean-file