遍历目录下的所有文件
假如有一个文件夹路径为dir,遍历文件
for file in /path/dir/* do if test -f $file then echo $file arrary=(${arrary[*]} $file) fi done echo ${arrary[@]}
这段代码可以读取目录dir下面的所有的文件名,如果dir目录中还有目录且该目录下的文件名也要求返回。
function get_all_file() { for temp in ./$1/* do if [ -f temp ]; then echo $temp arrary=(${arrary[*]} $temp) else get_all_file $temp } get_all_file dir echo ${arrary[@]}