I'm trying to rename files in folders for a bioinformatics project. There is a folder for each sample which is named, the files in the folders all have the same names which is no good for downstream processing so I am trying to rename them with a prefix. The prefix is chopped from the $folder, if I test it using for example " rename 's/^/bc01_/' * " it works fine, if I try to use the parameter expansion as mentioned it doesn't work, but I don't understand why? The error message given is below the code chunk, but the "$sampleID" is declared so I'm not understanding the error msg?
Any help much appreciated!
ls /homex/ddxxa/"$project"/medaka/barcode01Chop/
calls_to_draft.bam.bai
consensus.fasta
consensus.fasta.gaps_in_draft_coords.bed
consensus_probs.hdf
project=$1
refseq=$2
for folder in /homex/ddxxa/"$project"/medaka/*Chop/ ; # $folder = barcode01Chop
do
sampleID=`echo "$folder" | sed -e 's/^.*\(barcode\)/bc/'| sed -e 's/Chop\/$//'`
# $sampleID = bc01
rename 's/^/${sampleID}_/' *
# files renamed to
bc01_calls_to_draft.bam.bai
bc01_consensus.fasta
bc01_consensus.fasta.gaps_in_draft_coords.bed
bc01_consensus_probs.hdf
done
Error msg:
Global symbol "$sampleID" requires explicit package name (did you forget to declare "my $sampleID"?) at (user-supplied code).