我正在尝试将文件列表存储到一个数组中,然后再次遍历该数组。
以下是我从控制台运行 ls -ls
命令时得到的结果。
total 40
36 -rwxrwxr-x 1 amit amit 36720 2012-03-31 12:19 1.txt
4 -rwxrwxr-x 1 amit amit 1318 2012-03-31 14:49 2.txt
我编写的以下 bash 脚本用于将上述数据存储到 bash 数组中。
i=0
ls -ls | while read line
do
array[ $i ]="$line"
(( i++ ))
done
但是当我 echo $array
时,我什么也得不到!
仅供引用,我以这种方式运行脚本:./bashscript.sh
最佳答案
关于bash - 如何将目录文件列表存储到数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9954680/