[英]Regarding Unix shell script
我想從INFILE目錄中檢索以文件名“ BBSCGG_”或“ BCT_”或“ ACL_”或“ ASC”開頭的文件,並在for循環內進行處理
INFILE=/ext/test/fil1/
for infile name in file prefix
... if [[ -f ${fspec} ]] ; then
processing logic
else
processing logic
done
我該怎么做
for name in "$infile"{BBSCGG_,BCT_,ACL_,ASC}*
do
....
done
#!/bin/ksh
flag=0
set -o braceexpand
for file in {BBSCGG_,BCT_,ACL_,ASC_}*
do
if [ -f "$file" ];then
# do your stuff if there are files
flag=1
fi
done
if [ "$flag" -eq 0 ];then
echo "warning. empty"
fi
如果存在子目錄,您可能也想看看“ find”命令。 查看該先出。
ls -1 $INFILE/{BBSCGG_,BCT_,ACL_,ASC}* |while read FILE; do
# $FILE holds full pathname of each prefixed file.
# mmk go ...
done
如果您希望樹中 $INFILE
下的所有文件,請使用find
而不是ls
:
find $INFILE -name BBSCGG_\* -o \
-name BCT_\* -o \
-name ACL_\* -o \
-name ASC\* |while read FILE; do
# kthx
done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.