0

I have a few files whose names I have assigned into variables. (There may be n number of files). Those variables are passed into an array. Now I want to print the names of the original files using that array.

Since there can be n number of files, I cannot make a static list of file names. I need to make a tar of every file. In one case, there can be only 1 file, in other, there can be 2 or 3 or 4 files. So I am creating a generic script for this purpose.

export count=2
testlist0=abc 
testlist1=notabc
declare -a testlist_array[$count]
for ((i=0;i<${count};i++));
do
  testlist_array[$i]=testlist$i
done
echo ${testlist_array[@]}

But it is not printing the file names abc not abc.

3
  • 4
    Change inside of loop to var="testlist$i";testlist_array[$i]="${!var}" Commented Jun 14, 2016 at 13:06
  • @123 would you like to convert your perfectly good comment into an Answer? Commented Jun 29, 2016 at 23:56
  • @JeffSchaller It's a duplicate, can't be bothered finding it though. Commented Jun 30, 2016 at 6:59

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.