I want to assign the value in the filearray to the variable $filename0,$filename1...etc
how can I set automatically increment filename and assign correct value result should be like this $filename0=filearray[0] $filename1=filearray[1]
Right now, this is my code
filearray=('tmp1.txt' 'tmp2.txt' 'tmp3.txt' 'tmp4.txt' 'tmp5.txt')
let i=0
while (( i <= 4 ));
do
filename=${filearray[i]}
i=$(( i+1 ))
done
Sorry for the late update:
now, when there is an extension in the filename it will prompt
"syntax error: invalid arithmetic operator (error token is ".txt")"
but is ok when I echo $(filename1)
count=0
for i in ${filearray[@]};
do
count=$(( count +1 ))
declare filename$count=$i
done
y=0
while [ $y < $count ]
do
y=$(( y + 1 ))
echo $((filename$y))
done