I would like to create a bash script, but there are some parameters I want to be configurable. I have a main bash.sh script where I want to load in some commands. So far this is what the the original file looks like:
#!/bin/bash
source values.txt
for i in $(ls 3_TRIMMED/*_R1.* | sort -u); do echo STAR --genomeDir $ref_genome \
--readFilesIn ${i} ${i/_R1./_R2.} \
--runThreadN $runThread --outFileNamePrefix 5_ALIGNED/${i} \
--sjdbGTFfile $gtf_file \
--readFilesCommand gunzip -c ; done
Where $ref_genome $runThread $gtf_file is coming from a config file, with the help of source. So it turned out that I need more config options and with that way its not possible. So I worked around and made another file containing the command line I want to run in the loop:
>STAR
STAR --genomeDir $ref_genome --readFilesIn ${i} ${i/_R1./_R2.} --runThreadN $runThread --outFileNamePrefix 5_ALIGNED/${i} --sjdbGTFfile $gtf_file --readFilesCommand gunzip -c
STAR>
and a script that reads that line of command from the file:
star="$( awk '/>STAR/{flag=1; next} /STAR>/{flag=0} flag' test.sh)"
This reads the command in between the STAR tags and saves it as a string.
My problem is that when I use that string in the for loop, like:
for i in $(ls 3_TRIMMED/*_R1.* | sort -u); do echo $star; done
it creates the loop but the values what supposed to be coming from the source are not replaced:
STAR --genomeDir $ref_genome --readFilesIn ${i} ${i/_R1./_R2.} --runThreadN $runThread --outFileNamePrefix 5_ALIGNED/${i} --sjdbGTFfile $gtf_file --readFilesCommand gunzip -c
STAR --genomeDir $ref_genome --readFilesIn ${i} ${i/_R1./_R2.} --runThreadN $runThread --outFileNamePrefix 5_ALIGNED/${i} --sjdbGTFfile $gtf_file --readFilesCommand gunzip -c
STAR --genomeDir $ref_genome --readFilesIn ${i} ${i/_R1./_R2.} --runThreadN $runThread --outFileNamePrefix 5_ALIGNED/${i} --sjdbGTFfile $gtf_file --readFilesCommand gunzip -c
Is there a way to load in the values like in my original script?
Thank you!
envsubstto trigger the substitiution inside your$starstring. But perhaps an even better solution would be to take some time and design your complete script from scratch....