我正在尝试将列出的文件存储到一个数组中,然后再次遍历该数组。以下是我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