Sie*_*geX 50
要回答您的确切问题,请使用以下内容:
arr=( $(find /path/to/toplevel/dir -type f) )
Run Code Online (Sandbox Code Playgroud)
$ find . -type f
./test1.txt
./test2.txt
./test3.txt
$ arr=( $(find . -type f) )
$ echo ${#arr[@]}
3
$ echo ${arr[@]}
./test1.txt ./test2.txt ./test3.txt
$ echo ${arr[0]}
./test1.txt
Run Code Online (Sandbox Code Playgroud)
但是,如果你只想一次处理一个文件,你可以使用find
's -exec
选项,如果脚本有点简单,或者你可以循环查找返回的内容如下:
while IFS= read -r -d $'\0' file; do
# stuff with "$file" here
done < <(find /path/to/toplevel/dir -type f -print0)
Run Code Online (Sandbox Code Playgroud)
for i in `ls`; do echo $i; done;
Run Code Online (Sandbox Code Playgroud)
不能比那更简单!
编辑:嗯 - 根据丹尼斯威廉姆森的评论,似乎你可以!
编辑2:虽然OP专门询问如何解析输出ls
,但我只想指出,正如下面的评论员所说,正确答案是"你没有".使用for i in *
或类似.
归档时间: |
|
查看次数: |
53767 次 |
最近记录: |