简体   繁体   中英

reading parameters into cURL from a text file in bash

I have a following cURL command to execute soapui test in Jenkins. There I am passing two parameters variable1 and 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. How do I loop through all those values in my cURL command?

#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.

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 --form "project=/build.tool/.jenkins/jobs/$var1"  --form "suite=$var2"  host

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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