2

I have a groups of files in a folder. Each group is identified by characters 3-6 in the file name. I want to read in all the files of the group, count how many files there are, and then assign the file name to a variable made up of some letters and the counter. e.g. FILENAME$COUNTER. My code is almost working but there seems to be a problem with assigning the counter to the variable name.

I get this error for the line with code FILE$COUNTER=$i

line 12: FILE1=5_lib1ln1_BWA_ddrot_testonl_pe12.bam: command not found

This is exactly what I wanted for the variable name and assignment, but its saying command not found. I'm not sure why there is a command not found.

#!/bin/bash
## All files from the same group have the same LIB
LIB='lib1'
COUNTER=0

for i in 5_*.bam
do
    SAMPLIB=`echo $i | cut -c 3-6`
    if [ "$LIB" = "$SAMPLIB" ]; then
            let COUNTER++
            FILE$COUNTER=$i
    fi
NUMFILES=$COUNTER
done

1 Answer 1

1

Replace

FILE$COUNTER=$i

with

eval FILE$COUNTER=$i

See eval command in Bash and its typical uses for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.