Cp command works on command line but not in bash

The below command moves all the .vcf files into the directory.

cp /home/cmccabe/Desktop/test/vcf/overall/stats/*.vcf /home/cmccabe/Desktop/NGS/annovar

When I use a bash wrapper the target.txt gets created but the text files do not get copied. All the paths are the same, but not sure why its not working. Thank you :).

Bash

logfile=/home/cmccabe/Desktop/test/process.log
for file in /home/cmccabe/Desktop/test/vcf/overall/stats/*.vcf ; do
     echo "Start annovar creation: $(date) - file: $file"
     echo ${file##*/} >> /home/cmccabe/Desktop/NGS/annovar/target.txt
     cp /home/cmccabe/Desktop/test/vcf/overall/stats/*.vcf /home/cmccabe/Desktop/NGS/annovar
     echo "End annovar file creation: $(date) - file: $file"
done >> "$logfile"

You are not capturing the errors. Try:

logfile=/home/cmccabe/Desktop/test/process.log
for file in /home/cmccabe/Desktop/test/vcf/overall/stats/*.vcf ; do
     echo "Start annovar creation: $(date) - file: $file"
     echo ${file##*/} >> /home/cmccabe/Desktop/NGS/annovar/target.txt
     cp /home/cmccabe/Desktop/test/vcf/overall/stats/*.vcf /home/cmccabe/Desktop/NGS/annovar
     echo "End annovar file creation: $(date) - file: $file"
done 2>&1 >> "$logfile"

Also: Why are you copying every single file every loop? If you're trying to copy them one at a time, cp * destination/ isn't the way to do it.

1 Like

Thank you very much for your help and good point, I appreciate them :slight_smile: