这是在shell脚本攻略中看到的一个例子,作用是文件统计信息:
#!/bin/bash
#Filename=filestat.sh
if [ $# -ne 1 ];
then
echo $0 basepath;
exit
fi
path=$1
declare -a statarray;
while read line;
do
ftype=file -b "$line" | cut -d, -f1
let statarray["$ftype"]++;
done < <( find $path -type f -print )
echo ================= File types and counts =========================
for ftype in "${!statarray[@]}";
do
echo $ftype : ${statarray["$ftype"]}
done
执行:
sh -x filestat.sh /home/test/shell/
<' filestat.sh: line 18:
done < <( find $path -type f -print )'根据提示是done < <( find $path -type f -print )有问题
第一个<用于重定向,第二个<用于将子程序的输出转换成文件名。
初次使用该功能,不知道怎么改,有知道的吗?
http://iask.sina.com.cn/b/3686153.html
done <<< "find $path -type f -print
" 这样写 你的bash版本应该在3.0以上吧