Regarding Unix shell script
I want to retrieve the file from the INFILE directory which are be开发者_Go百科gining with the file names prefix "BBSCGG_" or "BCT_" or "ACL_" or "ASC" and do the processing inside the for loop
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
You may want to take a look at the "find" command too if subdirectories exist. Check this out first.
#!/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
:
find $INFILE -name BBSCGG_\* -o \
-name BCT_\* -o \
-name ACL_\* -o \
-name ASC\* |while read FILE; do
# kthx
done
精彩评论