Linux中

时间:2018-04-26 13:15:17

标签: linux bash

大家好!
我写了一个过去有效的脚本,但突然间它不起作用,我不明白为什么 这是我的剧本:

#!/bin/bash
#This script gets damage seq bed files of 4 nucleotides and filters only those with dipyrimidins in 2-3 position.
_pwd=/cs/icore/elisheva.h/Damage_seq/Sheera_4nt
#hg-19 ref genome.
genome_path="/cs/icore/elisheva.h/hg19-ref_genome/genome/hg_19_ref_genome.fa" 
#Scans all the damage seq given bed files.
for bedFile in $_pwd/*.bed
do
  #Removes duplicates lines.
  sort -u -o $bedFile  $bedFile 
  #Sorts the files according to chromosome and coordinates. 
  sort -k1,1 -k2,2n -o $bedFile  $bedFile 
  name=`basename $bedFile`
  #Adjusts the fasta file name. 
  faName="${name%.bed*}.fa"    
  bedtools getfasta -s -fi $genome_path -bed $bedFile -name -fo $_pwd/fasta_files/$faName #Gets the sequence itself.
done

#Scans all the obtained fasta files.
for faFile in $_pwd/fasta_files/*.fa
do
  name=`basename $faFile`
  faOutput="${name}"
  bedOutput="${name%.fa*}.bed"
  #Filters the files for getting only those which contain dypirimidne in 2-3 columns. 
  cat $faFile  |\
  paste - -  |\
  awk 'toupper(substr($2,2,2)) ~ /^(TT|TC|CT|CC)$/' |\
  tr "\t" "\n" |\
  tee $_pwd/filtered_fasta/$faOutput |\ 
  awk -F '[>():-]' '/^>/ {printf("%s\t%s\t%s\t%s\t%s\t%s\n",$4,$5,$6,$2,$2,$7);}' > $_pwd/filtered_bed/$bedOutput 
done

当我运行它时,我收到此错误:

line 30:  : command not found

第30行是这一行:

tee $_pwd/filtered_fasta/$faOutput |\ 

我不知道为什么会出现这种错误,之前它运作良好 我真的希望有人可以帮我解决这个问题。

更新:我删除了所有' \'它现在工作正常。

1 个答案:

答案 0 :(得分:2)

如果我认为您已正确粘贴脚本,则在反斜杠\之后的第30行中会有一个字符。

Bash本身告诉你未知命令的名称:

line 30:  : command not found

:之间的东西是Bash无法识别的命令名称,而这个东西是 - 一个空格。

根据评论中的建议,删除管道\后的反斜杠|,并确保管道符号是最后一个。这将提高可读性。

另外,好的编辑器可以显示空格(example for Sublime Text)。启用它会告诉你这样的错误。