divya.trehan573 divya.trehan573 - 16 days ago 6
Bash Question

bash command in shell script(If else erroring out)

#!/bin/bash

FILE_NAME=$1
FILE_LOCATION=$2
ENTITY_LIST=ALL
echo "FILE_NAME and location"
echo $FILE_NAME
echo $FILE_LOCATION

if [echo $FILE_NAME | awk -F"_" '{print $3}' = "IMAGE"];
then

F_NAME=echo $FILE_NAME | awk -F"_" '{print "UCM_"$3"_"$4}'
else

F_NAME=`echo $FILE_NAME | sed 's/FUSION_CONFIGURATION_1/UCM/'`
exit 0
fi

# exit 1 represents concurrent program status. 1 for error, 2 for warning 0 for success
echo "***********************************final*****************************"


This is giving an error syntax error at line 15 : `fi' unexpected

The if is closed with fi which is the correct syntax. Any suggestion on the error we are getting

Answer

Here is I think what you want to do

 #!/bin/bash
    #Note If you see # in front of any line it means that it’s a comment line not the actual code
    #** ********************************************************************
    # Description :
    #
    #** ********************************************************************

    FILE_NAME=$1
    FILE_LOCATION=$2
    ENTITY_LIST=ALL
    echo "FILE_NAME and location"
    echo $FILE_NAME
    echo $FILE_LOCATION

    if [[ $(echo $FILE_NAME | awk -F"_" '{print $3}') == "IMAGE" ]];
    then

     F_NAME=echo $FILE_NAME | awk -F"_" '{print "UCM_"$3"_"$4}'
    else

    F_NAME=`echo $FILE_NAME | sed 's/FUSION_CONFIGURATION_1/UCM/'`
    exit 0
    fi