我正在尝试使用bash
来验证特定下载.bam
文件的完整性。有两个部分(bash 1)运行命令来验证创建.bam
文件的.txt
文件,并创建process.log
。该部分工作正常,我收到错误的是检查每个.txt
文件中的字符串(SUCCESS)
,如果找到它,那么在process.log
该文件被验证,如果它找不到那个文件已损坏。目前,终端显示状态,然后给出错误。谢谢你:)。
bash第1部分
logfile=/home/cmccabe/Desktop/NGS/API/5-4-2016/process.log
for f in /home/cmccabe/Desktop/NGS/API/5-4-2016/*.bam ; do
echo "Start bam validation creation: $(date) - File: $f"
bname=`basename $f`
pref=${bname%%.bam}
bam validate --in $f --verbose 2> /home/cmccabe/Desktop/NGS/API/5-4-2016/bam_validation/${pref}_validation.txt
echo "End bam validation creation: $(date) - File: $f"
done >> "$logfile"
echo "Start verifying $(date) - File: $file"
value=$( grep -ic "(SUCCESS)" /home/cmccabe/Desktop/NGS/API/5-4-2016/bam_validation/*.txt )
bash第2部分
if [ $value -eq 1 ]
then
echo "bam file is verified and complete"
else
echo "bam is corrupt, check log for reason"
echo "End bam verify: $(date) - File: $f"
fi
done >> "$logfile"
erorr
Start verifying Thu May 5 12:49:10 CDT 2016 - File:
/home/cmccabe/Desktop/loop.sh: line 11: [: too many arguments
bam is corrupt, check log for reason
End bam verify: Thu May 5 12:49:10 CDT 2016 - File: /home/cmccabe/Desktop/NGS/API/5-4-2016/NA19240.bam
/home/cmccabe/Desktop/loop.sh: line 18: syntax error near unexpected token `done'
/home/cmccabe/Desktop/loop.sh: line 18: `done >> "$logfile"'
为检查SUCCESS而创建的文件
Number of records read = 24723078
Number of valid records = 24723078
TotalReads(e6) 24.72
MappedReads(e6) 24.57
PairedReads(e6) 0.00
ProperPair(e6) 0.00
DuplicateReads(e6) 7.33
QCFailureReads(e6) 0.00
MappingRate(%) 99.38
PairedReads(%) 0.00
ProperPair(%) 0.00
DupRate(%) 29.66
QCFailRate(%) 0.00
TotalBases(e6) 4332.46
BasesInMappedReads(e6) 4325.68
Returning: 0 (SUCCESS)
答案 0 :(得分:1)
错误是由于最简单的原因,bash
如果你使用单个括号[]
来评估一个条件,它只不过是隐含的使用bash {{1}的方法。 } expression,它将test
扩展为包含空格的字符串,将特殊字符作为单独的参数。在这里你留下了变量模糊,可以扩展到一些错误情况下的多个参数。
您需要做的就是将该变量括在双引号中,以便将其视为一个单独的字符串。
$value