首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

写了一个sh脚本,执行的时候出现如上语法异常,如何解决

2012-09-22 
写了一个sh脚本,执行的时候出现如下语法错误,怎么解决脚本信息:文件名:filestat.sh文件内容:if [ $# -ne 1

写了一个sh脚本,执行的时候出现如下语法错误,怎么解决
脚本信息:
文件名:filestat.sh
文件内容:
if [ $# -ne 1 ];
then
  echo $0 basepath;
  echo
fi
path=$1

declare -a statarray;

while read line;
do
  ftype=`file -b "$line"`
  let statarray["$ftype"]++;
done<< (find $path -type f -print)

echo===============file types and counts===================
for ftype in "${!statarray[@]}";
do
  echo $ftype:${statarray["$ftype"]}
done


运行结果:
[zhang@localhost temp]# ./filestat.sh
./filestat.sh basepath

./filestat.sh: line 14: syntax error near unexpected token `('
./filestat.sh: line 14: `done<< ( find $path -type f -print );'

[解决办法]
done<< (find $path -type f -print)
这样用比较奇怪吧,先把结果保存到一个文件,再重定向试试。
[解决办法]
<<需要的是文件描述符
要想将find $path -type f -print结果read,使用for line in $(find $path -type f -print);do xxxx;done
[解决办法]
正解
for line in `find $path -type f -printf`
do
XXX
done


探讨

谢谢,但是我想知道,这样做的错误如何改正引用:
done<< (find $path -type f -print)
这样用比较奇怪吧,先把结果保存到一个文件,再重定向试试。

热点排行