2

Hi everyone!
I wrote a script that worked in the past, but suddenly it does not work and I have no idea why.
Here is my script:

#!/bin/bash
#This script gets damage seq bed files of 4 nucleotides and filters only those with dipyrimidins in 2-3 position.
_pwd=$PWD
#hg-19 ref genome.
genome_path="/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

When I run it, I get this error:

line 30:  : command not found

where line 30 is this line:

tee $_pwd/filtered_fasta/$faOutput |\ 

I have no idea why this error occurs, it worked fine before.
I really hope someone can help me with that issue.

UPDATE: I deleted all the '' and it works fine now.

Elizabeth
  • 282
  • 1
  • 6
  • 16
  • 3
    FWIW, the backslashes after the pipe characters are not necessary. As long as the pipe character is the last character on a line, the shell knows to use the next line as the next pipe segment. But .. try running your script through http://shellcheck.net. You'll get tips for many improvements which may make debugging easier. – ghoti Apr 26 '18 at 13:18
  • 2
    The error is consistent with that line ending with a carriage return (`\r`). – chepner Apr 26 '18 at 13:26
  • Also see [How to use Shellcheck](https://github.com/koalaman/shellcheck), [How to debug a bash script?](https://unix.stackexchange.com/q/155551/56041) (U&L.SE), [How to debug a bash script?](https://stackoverflow.com/q/951336/608639) (SO), [How to debug bash script?](https://askubuntu.com/q/21136) (AskU), [Debugging Bash scripts](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html), etc. – jww Apr 27 '18 at 00:17

1 Answers1

2

If I should believe that you've pasted your script correctly, there is a character in line 30 after the backslash \.

The Bash itself is telling you name of the unknown command:

line 30:  : command not found

The thing between : is name of command that Bash was unable to recognize and this thing is - a white space.

As suggested in comments, remove the backslashes \ after pipe | and make sure that the pipe character is the last one in line. This will improve readability.

Also, good editor can show white spaces (example for Sublime Text). Enabling it will show you such mistakes.

smbear
  • 1,007
  • 9
  • 17