Search code examples
shellsh

need to exclude the few values while using if condition


I have two files having the values where i need to ignore mov_order and process the account in few cases. Can someone help me to fix the issue

file1: 
input_file='/efs/home/ps604312/testing_vela/entity_list.txt'
staging staging-modules mov_order
staging staging-modules account

file2:
OTHER_ENTITY_LIST='/efs/home/ps604312/testing_vela/other_entity_list.txt'
if [[ "${ENTITY_NAME}" != "${OTHER_ENTITY_NAME}"  &&  "${PRODUCT_ENTITY}" == "staging" ]];

then
        echo "syncing only "${ENTITY_NAME}" entity"
        echo "folder "${ENTITY_NAME}" is exist"

        rsync -avzh ${SOURCE_PATH}/"${ENTITY_NAME}" ${DESTINATION_PATH}/"${ENTITY_NAME}"

else

           rsync -avzh ${SOURCE_PATH}/"${ENTITY_NAME}" ${DESTINATION_PATH}/"${ENTITY_NAME}"

      fi

Solution

  • I believe what you are looking for is using multiple conditions in single if statement. The following snippet gives an easy illustration for the same

    ## function with multiple if conditions with && operator
    
    firstArg=true
    secondArg=false
    thirdArg=true
    fourthArg=true
    
    
    function test {
        if [ $firstArg == "true" ] && [ $secondArg == "true" ]; then
            echo "first and second are true"
        elif [ $thirdArg == "true" ] && [ $fourthArg == "true" ]; then
            echo "third and fouth are true"
        else
            echo "None was true"
        fi
    }
    
    
    test
    
    • Run
    ╰─ bash test.sh
    third and fouth are true