简体   繁体   English

从bash中的文本文件将参数读取到cURL中

[英]reading parameters into cURL from a text file in bash

I have a following cURL command to execute soapui test in Jenkins. 我有以下cURL命令在Jenkins中执行soapui测试。 There I am passing two parameters variable1 and variable2. 我在这里传递了两个参数variable1和variable2。

curl --form "project=/build.tool/.jenkins/jobs/$variable1"  --form "suite=$variable2"  host

I have a following .txt file where values for those variables are in two columns separated by a space. 我有一个以下.txt文件,其中这些变量的值在两列中以空格分隔。 How do I loop through all those values in my cURL command? 如何在cURL命令中遍历所有这些值?

#file1.txt
project1.xml TestSuite_1
project1.xml TestSuite_2
project2.xml TestSuite_3
project2.xml TestSuite_4
project3.xml TestSuite_5

Used this on your test input 在您的测试输入上使用了这个

while read p; do
  var1=`echo $p | awk '{print $1" "}'`
  var2=`echo $p | awk '{ print " "$2}'`
  echo $var1
  echo $var2
done <infile

Where infile contains your data. infile包含您的数据的位置。

It output: 输出:

project1.xml
TestSuite_1
project1.xml
TestSuite_2
project2.xml
TestSuite_3
project2.xml
TestSuite_4
project3.xml
TestSuite_5

Now you've got them stored in variables, and you can just add them to your curl command 现在,您已经将它们存储在变量中,您可以将它们添加到curl命令中

curl --form "project=/build.tool/.jenkins/jobs/$var1"  --form "suite=$var2"  host

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM