我试图将文件列表存储到一个数组中,然后再次遍历数组。 以下是当我从控制台运行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
'<(ls -ls)'你介意解释一下符号吗?我不明白为什么它不只是'LS -ls' – imagineerThat 2014-01-14 23:41:53
见http://mywiki.wooledge.org/ProcessSubstitution – Mat 2014-01-15 04:36:56