0

Overview:

I want to code a function that will keep on executing till the value is equal to 0 and if the value is greater than 0, I'm writing the value into file and break-ing the loop.

Problem:

If the function is executed 8 times then while exiting the function in case the value is greater than 0 then 8 times the value is written into the file instead of 1 time. Kindly help me with the issue I'm facing.

PFB the code used,

#!/usr/bin/ksh

    fx_Running()
    {
        v_line=$1
        v_SRC_NM=$2

        v_VAR =`echo $v_line|awk -F',' '{print $1}'`

        v_STATUS=`wc -l $v_VAR | awk '{print $1}`

        if [ $v_STATUS == 0 ]
        then
            fx_Running $v_line $v_SRC_NM 
        fi

        if [ $v_STATUS == 1 -o $v_STATUS == 2 ]
            then
                ${v_line} >> ${v_COMPLETED_LIST}
                break
        fi

        if [ $v_JOB_STATUS == 3 ]
        then        
            ${v_line} >> ${v_FAILED_LIST}
            break
        fi

    }
1
  • 2
    Why does your title mention bash if your script starts with #!/usr/bin/ksh? Commented Apr 22, 2016 at 11:05

1 Answer 1

1

Using break is incorrect, use return instead. Specifically break exits a loop, whereas return exits a function.

Here's a demo of the problem:

foo(){ break ; } ; for f in `seq 10` ; do echo $f ; foo ; done

Output:

1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.