There are some files in my work directory like below:
20191101.data.lz4
20191104.data.lz4
20191105.data.lz4
20191106.data.lz4
20191107.data.lz4
20191108.data.lz4
20191111.data.lz4
20191112.data.lz4
20191113.data.lz4
20191114.data.lz4
20191115.data.lz4
20191118.data.lz4
20191119.data.lz4
Now I need to process these files. If I use below command defin a array the for
loop work as my expect, print all file in my work directory.
FILE_LIST=$(ls /my/work/dir)
for EACH_FILE in ${FILE_LIST}
do
echo $EACH_FILE
done
But if I defin array as below, the for
loop only print the first element of array.
FILE_LIST=(20191101.data.lz4
20191104.data.lz4
20191105.data.lz4
20191106.data.lz4
20191107.data.lz4
20191108.data.lz4
20191111.data.lz4
20191112.data.lz4
20191113.data.lz4
20191114.data.lz4
20191115.data.lz4
20191118.data.lz4
20191119.data.lz4)
for EACH_FILE in ${FILE_LIST}
do
echo $EACH_FILE
done
But I found I can iterate every element of second array in below way:
for EACH_FILE in ${FILE_LIST[*]}
do
echo $EACH_FILE
done
In this question most answer explained how to use for
loop in seconds way, but it didn't explain why my first way not working. Based on this answer's situation B, my first way should works fine, but it didn't.
I am still pretty confuse why the second arraya can't iterate by the first way?
Thankyou in advance!