如果使用 -f 命令不起作用

如果使用 -f 命令不起作用
#!/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

另请参考此链接

相关内容