#!/bin/sh
#used for copying files from searscsg/searscsg/in to searscsg/servicebench/in
SEARS_CSG_INDIR=$MFRDATA/searscsg/searscsg/in
SEARS_NCC_INDIR=$MFRDATA/searsncc/searsncc/in
MFRNAME=Sears
RUN_DAILY=1
RUN_FIFTEEN=1
RUN_JCMONLY=1
SEARS_SB_INDIR=$MFRDATA/searscsg/servicebench/in
# function for building up a list of files into a variable
addtofilelist()
{
RETVAL=""
while [ $# -gt 0 ]; do
if [ "$1" != "" ]; then
if [ "$RETVAL" = "" ]; then
RETVAL="$1"
else
RETVAL="$RETVAL $1"
fi
fi
shift
done
echo "$RETVAL"
}
if [ $RUN_DAILY -eq 1 ]; then
# Daily
echo "Including daily files."
FILE_LIST=`addtofilelist csssbzip contractorcostimport MPICKUP.txt CONFPAY cntrpymt contractorMDOlocations contractorJobCode"$FILE_LIST"`
fi
if [ $RUN_JCMONLY -eq 1 ]; then
# Daily
echo "Including daily files."
FILE_LIST=`addtofilelist STKNUMCLS "$FILE_LIST"`
fi
if [ $RUN_FIFTEEN -eq 1 ]; then
# 15 minutes
echo "Including 15 minute files."
FILE_LIST=`addtofilelist ASASOSTSCHG NEWASASO NEWASISO INSSOUNM INSSO CLSINSSO INSOO "$FILE_LIST"`
fi
echo "copying files in the list"
for fileName in $FILE_LIST; do
echo "$SEARS_CSG_INDIR/$fileName"
if [ -f /home/serviceb/dev/batch/mfrdata/searscsg/searscsg/in/fileName ]; then
echo "Attempting to copy $fileName ..."
cp $fileName $SEARS_SB_INDIR
elif [ -f $SEARS_NCC_INDIR/$fileName ]; then
cp $fileName $SEARS_SB_INDIR
else
echo "File Not Found $fileName"
fi
fi
done
echo "$FILE_LIST"
#-----Done
답변1
직접 확인하실 수 있어요여기,
$ shellcheck myscript
Line 50:
for fileName in $FILE_LIST; do
^-- SC1073: Couldn't parse this for loop.
^-- SC1061: Couldn't find 'done' for this 'do'.
Line 60:
fi
^-- SC1062: Expected 'done' matching previously mentioned 'do'.
^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.
답변2
if 문을 이해하는 데 도움이 되는 아래 예를 확인하세요.
#!/bin/bash
if [ -f "$1" ]
then
echo "$1 is a file"
else
echo "$1 is not a file"
fi