如何将 ls 分配给 Linux Bash 中的数组? [英] How do I assign ls to an array in Linux Bash?
本文介绍了如何将 ls 分配给 Linux Bash 中的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
array=${ls -d */}
echo ${array[@]}
我有三个目录:ww
ee
qq
.我希望它们在一个数组中,然后打印该数组.
I have three directories: ww
ee
qq
. I want them in an array and then print the array.
推荐答案
就是这样
array=($(ls -d */))
请参阅戈登戴维森的解决方案以获得更一般的答案(即,如果您的文件名包含特殊字符).这个答案只是语法更正.
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.
这篇关于如何将 ls 分配给 Linux Bash 中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文