Entering edit mode
3.0 years ago
j_weld
▴
10
I am trying to run bash script, but it gives this error ( `$fastq': not a valid identifier).
I am trying to run bash script, but it gives this error ( `$fastq': not a valid identifier).
It should be for fastq in
, not for $fastq in
. Variables don't get the $
when they're being declared/initialized/assigned to.
#!/bin/bash
database="kraken2_database"
fastq="fastq_dir" # consider change this variable name, you repeat it in the loop variable (sorry if this is what you wanted to do.)
for fastq in $(ls *_R1.fastq.gz | sed 's/_R1.fastq.gz//') # <---- the problem was the "$fastq"
do
# also, the '\' are needed
kraken2 --db $database \
--threads 8 --memory-mapping \
--use-names --confidence 0.1 \
--report taxonomy_reads/${fastq}_kraken2.tax \
--paired ${fastq}_R1.fastq.gz ${fastq}_R2.fastq.gz \
--output taxonomy_reads/${fastq}_kraken2.txt
done
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Do you get valid names if you just run this:
ls *_R1.fastq.gz | sed 's/_R1.fastq.gz//'
yes, when I am running
ls *_R1.fastq.gz | sed 's/_R1.fastq.gz//'
in my fastq folder it gives me namesHi ! try running your script with "bash -x yr_script.sh", this will expand variables and print commands line by line.
Also, add a '\' :
Okay, I tried, but it also gives the same line error `$fastq': not a valid identifier