How do I assign ls to an array in Linux Bash?

前端 未结 3 1094
孤街浪徒
孤街浪徒 2020-12-01 00:50
array=${ls -d */}
echo ${array[@]}  

I have three directories: ww ee qq. I want them in an array and then pr

3条回答
  •  遥遥无期
    2020-12-01 01:51

    It would be this

    array=($(ls -d */))
    

    EDIT: See Gordon Davisson's solution for a more general answer (i.e. if your filenames contain special characters). This answer is merely a syntax correction.

提交回复
热议问题