只是做为一个shell的小小练习和平常统计用,瞎折腾的过程当中也是摸到了获取子shell返回值的几种方法;
确定还有别的方法,跟进程间的通讯相关,但愿你能提出建议和补充,谢谢~shell
#! /bin/bash #检查参数数量是否符合要求 if [ $# -ne 1 ] then echo How to use: $0 ---> basepath! exit -1 fi #获取传入的路径参数 path=$1 #声明一个关联数组 declare -A typearray while read fileinfo do ftype=`file -b "$fileinfo" | cut -d , -f 1` let typearray["$ftype"]++ done< <( find $path -type f -print ) echo '==File==Type==Stastics==' for ftype in "${!typearray[@]}" do echo $ftype : ${typearray["$ftype"]} done
#这段放在while以前 if [ ! -p npipe ] then mkfifo -m 777 npipe fi #替换掉得到ftype值那里 ( file -b "$fileinfo" | cut -d , -f 1 > npipe & ) read ftype<npipe
#替换掉得到ftype值那里 ( file -b "$fileinfo" | cut -d , -f 1 )>temp.txt read ftype<temp.txt
#替换掉得到ftype值那里 read type << HERE `file -b "$fileinfo" | cut -d , -f 1` HERE