How to store directory files listing into an array?

前端 未结 5 685
清酒与你
清酒与你 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:38

    Running any shell command inside $(...) will help to store the output in a variable. So using that we can convert the files to array with IFS.

    IFS=' ' read -r -a array <<< $(ls /path/to/dir)
    

提交回复
热议问题