bash script not a valid identifier
2
0
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).

kraken2 bash • 3.2k views
ADD COMMENT
0
Entering edit mode

Do you get valid names if you just run this: ls *_R1.fastq.gz | sed 's/_R1.fastq.gz//'

ADD REPLY
0
Entering edit mode

yes, when I am running ls *_R1.fastq.gz | sed 's/_R1.fastq.gz//' in my fastq folder it gives me names

ADD REPLY
0
Entering edit mode

Hi ! try running your script with "bash -x yr_script.sh", this will expand variables and print commands line by line.

Also, add a '\' :

 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
ADD REPLY
0
Entering edit mode

Okay, I tried, but it also gives the same line error `$fastq': not a valid identifier

ADD REPLY
1
Entering edit mode
3.0 years ago
Ram 44k

It should be for fastq in, not for $fastq in. Variables don't get the $ when they're being declared/initialized/assigned to.

ADD COMMENT
0
Entering edit mode

I knew that the other way around. But in that case it gives this '*_R1.fastq.gz': 'No such file or directory' , but I tried this on my fastq files and it worked.

ADD REPLY
0
Entering edit mode

Do not delete posts when they've been addressed. If one or more solutions worked, accept them using the green check mark.

upvote_bookmark_accept

ADD REPLY
0
Entering edit mode
3.0 years ago
hugo.avila ▴ 530
#!/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
ADD COMMENT

Login before adding your answer.

Traffic: 1710 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6