日期:2014-05-16  浏览次数:20687 次

一个shell脚本的一条语句不知道怎么理解
我最近在学习shell脚本,教材中有一个小脚本,中间有一段代码(读取目录下的文件类型),如下

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

关键是那个done后面的< <怎么理解?如果写成<<是显然不行的,写成<的时候也报错误
shell

------解决方案--------------------
   Process Substitution
       Process  substitution  is supported on systems that support named pipes
       (FIFOs) or the /dev/fd method of naming open files.  It takes the  form
       of  <(list) or >(list).  The process list is run with its input or out-
       put connected to a FIFO or some file in /dev/fd.  The name of this file
       is  passed  as  an argument to the current command as the result of the
       expansion.  If the >(list) form is used, writing to the file will  pro-
       vide  input  for list.  If the <(list) form is used, the file passed as
       an argument should be read to obtain the output of list.

       When available, process substitution is performed  simultaneously  with
       parameter  and variable expansion, command substitution, and arithmetic
       expansion.

------解决方案--------------------
〈&