1

I have the following bash script:

#!/bin/bash

for r in $(find . -name "*.fastq");
do

  cat <<EOF
  #qsub <<EOF
#!/bin/bash -l

#PBS -N $r

EOF

done

Unfortunately, all filename get split:

> sh  cFiltering_pbs.sh 
  #qsub <<EOF
#!/bin/bash -l

#PBS -N ./76A

  #qsub <<EOF
#!/bin/bash -l

#PBS -N Paired.fastq

  #qsub <<EOF
#!/bin/bash -l

#PBS -N ./104A

  #qsub <<EOF
#!/bin/bash -l

#PBS -N Paired.fastq

Here is the find output:

find . -name "*.fastq"
./76A Paired.fastq
./104A Paired.fastq

What did I miss?

1 Answers1

2

Instead of using find you can simply loop through the files themselves. Notice that I have double-quoted "$r"; you need to do that to keep the space in the filenames intact and unparsed by the shell.

for r in *.fastq
do
    # Stuff using "$r"...
    :
done
Chris Davies
  • 116,213
  • 16
  • 160
  • 287