0

I am trying to read the contents of a csv and pass it to another function using shell scripting. I am new to shell scripting and cannot figure out how to do it.

ConvertedCSVpath="/home/test/Desktop/Outfile.csv"

    converttoCSV()
    {
    for i   in /home/test/repos/pgp-automation/TestSuite/Suite1495088054448/Outfile.xlsx; 
    do  libreoffice --headless --convert-to csv "$i" ; 
    done
    IFS=,
    while read Tstcase OrderID MID
    do 
        echo "Testcase: -> $Tstcase"
        echo "OrderID: $OrderID"
        echo "ID: $MID" 
    done < $ConvertedCSVpath
    }

It has converted to CSV file

TestCase_002-,1495088066891,atoRef79606157945546 TestCase_002,218271828172187,C192819821981

    PassVariable()
    {
    echo The order ID is $OrderID
    }

    converttoCSV
    PassVariable

I need to take the OrderID and use it in PassVariable function one by one. i.e, first it should take 1495088066891 and pass it to PassVariable and then 218271828172187 and again pass it to PassVariable and print. How can I do this?

1 Answers1

0

I'm not sure to understand what you try to achieve, but if the question is how to call a bash function with a parameter and how to use it in the called function, this is how you do it :

PassVariable() {
  echo $1 # Print first parameter
}

PassVariable "$OrderID"

See this for more informations : Passing parameters to a Bash function

Community
  • 1
  • 1
Esteban
  • 1,752
  • 1
  • 8
  • 17