日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

统计文件种类数+获取子shell返回值的其它方法

發布時間:2023/11/27 生活经验 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 统计文件种类数+获取子shell返回值的其它方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

只是作為一個shell的小小練習和日常統計用,瞎折騰的過程中也是摸到了獲取子shell返回值的幾種方法;
肯定還有別的方法,跟進程間的通信相關,希望你能提出建議和補充,謝謝~

完整程序:

#! /bin/bash
#檢查參數數量是否符合要求
if [ $# -ne 1 ]
thenecho How to use: $0 ---> basepath!exit -1
fi
#獲取傳入的路徑參數
path=$1
#聲明一個關聯數組
declare -A typearraywhile read fileinfo
doftype=`file -b "$fileinfo" | cut -d , -f 1`let typearray["$ftype"]++
done< <( find $path -type f -print )echo '==File==Type==Stastics=='
for ftype in "${!typearray[@]}"
doecho $ftype : ${typearray["$ftype"]}
done

獲取子shell返回值的其它方法:

  1. 使用管道
#這段放在while之前
if [ ! -p npipe ]
then mkfifo -m 777 npipe
fi
#替換掉獲得ftype值那里
( file -b "$fileinfo" | cut -d , -f 1 > npipe & )
read ftype<npipe
  1. 使用臨時文件
#替換掉獲得ftype值那里
( file -b "$fileinfo" | cut -d , -f 1 )>temp.txt
read ftype<temp.txt
  1. 使用HERE文檔
#替換掉獲得ftype值那里
read type << HERE
`file -b "$fileinfo" | cut -d , -f 1`
HERE

轉載于:https://www.cnblogs.com/annsshadow/p/5153872.html

總結

以上是生活随笔為你收集整理的统计文件种类数+获取子shell返回值的其它方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。