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

Jordin Youssef picture Jordin Youssef · Sep 19, 2013 · Viewed 120.5k times · Source
array=${ls -d */}
echo ${array[@]}  

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

Answer

Aaron Okano picture Aaron Okano · Sep 19, 2013

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.