Separating list of input files (*.file) with a comma in bash script

Hi all,

I'm trying to get a bash script working for a program (bowtie) which takes a list of input files (*.fastq) and assembles them to an output file (outfile.sam). All the .fastq files are in one folder in my home directory (~/infiles).

The problem is that the 'bowtie' requires that the input files are separated by a comma and with no space in between. E.g.:

infile1.fastq,infile2.fastq,infile3.fastq ...

Does anyone know how I could do this?

#!/bin/bash
fn=*.fastq
./bowtie [parameters] index_file ~/infiles/$fn outfile.sam &

How it should run at the end:

./bowtie [parameters] index_file ~/infiles/infile1.fastq,infile2.fastq,infile3.fastq,infile4.fastq outfile.sam

Your help is greatly appreciated!
Best

for i in *.fastq; my_variable=`echo $my_variable$i; done

./bowtie [parameters] index_file ~/infiles/$my_varibale outfile.sam  

1 Like

Many thanks for your reply!

Can it be that a (`) is missing? When I run the command I get an error message (below). Sorry, I'm new to bash:o

#!/bin/bash

for i in *.fastq; my_variable=`echo $my_variable$i; done

./bowtie index_file $my_variable outfile.sam 

Error:
./test2.sh: line 3: unexpected EOF while looking for matching ``'
./test2.sh: line 15: syntax error: unexpected end of file

Many thanks again!

for i in *.fastq; my_variable=`echo $my_variable$i`; done

Thanks! I tried this but I still get an error:

./test2.sh: line 3: syntax error near unexpected token `my_variable=`echo $my_variable$i`'
./test2.sh: line 3: `for i in *.fastq; my_variable=`echo $my_variable$i`; done'

sorry, i forget the do word

for i in *.fastq; do my_variable=`echo $my_variable$i`; done

...works:) Could also have thought of the 'do', sorry.

Many thanks again!

This is a useless use of backticks. Why have var=`echo something` when you could just do var="something" ?

In this case my_variable="${my_variable}${i}"