[英]Regarding Unix shell script
I want to retrieve the file from the INFILE directory which are begining with the file names prefix "BBSCGG_" or "BCT_" or "ACL_" or "ASC" and do the processing inside the for loop 我想从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
how can i do it 我该怎么做
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
ls -1 $INFILE/{BBSCGG_,BCT_,ACL_,ASC}* |while read FILE; do
# $FILE holds full pathname of each prefixed file.
# mmk go ...
done
If you want all files in the tree under $INFILE
then use find
rather than ls
: 如果您希望树中
$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.