0

how can i pass parameter to function in linux. I am reding line by line in a file and run the esch record in background

while read -r record
    do
        reccount=$(( reccount + 1 ))
        #function call  
        proceed_tasks_function(record) &
done

to the function

proceed_tasks_function(/*take the record from function call*/)
{
### parse input record

          contact_email=`echo "$record" | cut -f5 -d ''`
              echo "contact email is $contact_email" 
          credit_card_id=`echo "$record" | cut -f6 -d ''`
              echo "credit card id is $credit_card_id"
          ref_nr=`echo "$record" | cut -f7 -d ''`
              echo "reference nr is $ref_nr"
          cny_cd=`echo "$record" | cut -f8 -d ''`
              echo "country code is $cny_cd"
          lang=`echo "$record" | cut -f9 -d ''`
              echo "language is $lang"
          pmt_ir=`echo "$record" | cut -f13 -d ''`
              echo "payment ir is $pmt_ir"
}
0

1 Answer 1

0

A function in shell is like any other command: arguments are simply listed after the command, no parentheses needed or allowed.

while read -r record
    do
        reccount=$(( reccount + 1 ))
        proceed_tasks_function "$record" &
done
Sign up to request clarification or add additional context in comments.

1 Comment

And from inside the function, you can refer to passed parameters with $1, $2, $*, following the same syntax as scripts argument

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.