How to store directory files listing into an array?

前端 未结 5 732
清酒与你
清酒与你 2021-01-30 13:10

I\'m trying to store the files listing into an array and then loop through the array again. Below is what I get when I run ls -ls command from the console.

5条回答
  •  情书的邮戳
    2021-01-30 13:40

    Here's a variant that lets you use a regex pattern for initial filtering, change the regex to be get the filtering you desire.

    files=($(find -E . -type f -regex "^.*$"))
    for item in ${files[*]}
    do
      printf "   %s\n" $item
    done
    

提交回复
热议问题