variable not showing up in bash script when using an array -


i have script prepare files submit trough qsub cluster, creating array based on file , using elements in array create qsub files. however, can't append variables $rawdata/$i_1.fastq.gz part. script:

> cat create.sh #!/bin/bash   rawdata="/home/jfertaj/data/fastq"    # make array of each sample id   mapfile -t myarray < array.txt   in "${myarray[@]}"        cat > pbs.script.$i << eof  #!/bin/bash   kallisto quant -t 16 -b 100 -o /home/jfertaj/data/results_kallisto/output_bootstrap_$i $rawdata/$i_1.fastq.gz $rawdata/$i_2.fastq.gz   eof  done  exit 0; 

when run bash script , created files see this:

... kallisto quant -t 16 -b 100 -o /home/jfertaj/data/results_kallisto/output_bootstrap_intp_993 /home/jfertaj/data/fastq/.fastq.gz /home/jfertaj/data/fastq/.fastq.gz  

i have tried including "$i" shows on resulting files: "intp_993"_1.fastq.tz. there way fix it?

replace $rawdata/$i_1.fastq.gz $rawdata/$i_2.fastq.gz $rawdata/${i}_1.fastq.gz $rawdata/${i}_2.fastq.gz.

that is, change this:

kallisto quant -t 16 -b 100 -o /home/jfertaj/data/results_kallisto/output_bootstrap_$i $rawdata/$i_1.fastq.gz $rawdata/$i_2.fastq.gz 

to this:

kallisto quant -t 16 -b 100 -o /home/jfertaj/data/results_kallisto/output_bootstrap_$i $rawdata/${i}_1.fastq.gz $rawdata/${i}_2.fastq.gz 

the shell treats i_1 , i_2 variable names, when want variable i appended "_1" , "_2". in such situations, when need use variable somevar followed suffix starting symbols valid in variable names, let's _suffix, need use braces identify variable. instead of $somevar_suffix need write ${somevar}_suffix.

this mentioned in man bash, emphasis mine:

${parameter}

the value of parameter substituted. the braces required when parameter positional parameter more 1 digit, or when parameter followed character not interpreted part of name. [...]


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -