array=${ls -d */} echo ${array[@]}
I have three directories: ww ee qq. I want them in an array and then print the array.
ww
ee
qq
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.
2.1m questions
2.1m answers
60 comments
57.0k users