Bash 从CSV读取值并将其传递给另一个函数[使用Shell脚本]
我正在尝试读取csv的内容,并使用shell脚本将其传递给另一个函数。我不熟悉shell脚本,不知道如何做Bash 从CSV读取值并将其传递给另一个函数[使用Shell脚本],bash,shell,unix,scripting,sh,Bash,Shell,Unix,Scripting,Sh,我正在尝试读取csv的内容,并使用shell脚本将其传递给另一个函数。我不熟悉shell脚本,不知道如何做 ConvertedCSVpath="/home/test/Desktop/Outfile.csv" converttoCSV() { for i in /home/test/repos/pgp-automation/TestSuite/Suite1495088054448/Outfile.xlsx; do libreoffice --headles
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
}
我需要获取OrderID并在PassVariable函数中逐个使用它。i、 首先,它需要1495088066891并将其传递给PassVariable,然后218271828172187并再次传递给PassVariable并打印。我怎样才能做到这一点呢?我不确定您想要实现什么,但如果问题是如何使用参数调用bash函数以及如何在调用的函数中使用它,那么您就是这样做的:
PassVariable() {
echo $1 # Print first parameter
}
PassVariable "$OrderID"
有关更多信息,请参见此链接:我已经找到了答案。在这种情况下,最好使用awk的IFS和While循环。无论如何,谢谢。:)
PassVariable() {
echo $1 # Print first parameter
}
PassVariable "$OrderID"