这是在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/
- '[' 1 -ne 1 ']'
- path=/home/test/shell/
- declare -a statarray
filestat.sh: line 18: syntax error near unexpected token
<' filestat.sh: line 18:
done < <( find $path -type f -print )'
根据提示是done < <( find $path -type f -print )有问题
第一个<用于重定向,第二个<用于将子程序的输出转换成文件名。
初次使用该功能,不知道怎么改,有知道的吗?