I want a shell script to process many input files. I am using variables for input names and renaming intermediate files. I am unable to redirect output to a filename.
The shell script is run like this:
./trim_pair_align_ab1.sh 116102 128861
The script can echo the variables correctly (lines 15 and 16) and they match expectation.
./temp/45739_1_PET22-001_116102_00_trim.fastq
./temp/45739_1_PET22-001_116102_00_trim.fasta
It can't evaluate the filename when the command redirects output
line 17: temp/$(echo $f|sed 's/_trim.fastq/_trim.fasta/'): No such file or directory
8 for f in *.fastq
9 do
10 seqtk trimfq -q 0.05 $f > ./temp/$(echo $f|sed 's/.fastq/_trim.fastq/')
11 done
12
13 for f in `eval ls ./temp/*$1*_trim.fastq`;
14 do
15 echo $f
16 echo $(echo $f|sed 's/_trim.fastq/_trim.fasta/')
17 seqtk seq -A $f > ./temp/$(echo $f|sed 's/_trim.fastq/_trim.fasta/')
18 done
Why does the output redirect work on line 10 but not on line 17? What is making line 17 literal rather than evaluated?
filename=./temp/$(echo $f|sed 's/_trim.fastq/_trim.fasta/')thenecho "$filename". Thisfor f in eval ls ./temp/*$1*_trim.fastq;is a strange way of doing things, why do you needls? Why not justfor f in ./temp/*"$1"*_trim.fastq?echo $finstead ofecho "$f") are also sources of additional hard-to-predict behavior. See BashPitfalls #14.seqtk seq -A "$f" >"./temp/$(sed 's/_trim.fastq/_trim.fasta/' <<<"$f")"sedat all, instead of going the much more efficient route and using a parameter expansion instead.for f in ./temp/*$1*_trim.fastqinstead.