【问题标题】:reading parameters into cURL from a text file in bash从 bash 中的文本文件将参数读入 cURL
【发布时间】:2016-10-24 00:53:31
【问题描述】:

我有一个以下 cURL 命令来在 Jenkins 中执行 soapui 测试。在那里我传递了两个参数 variable1 和 variable2。

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

我有一个以下 .txt 文件,其中这些变量的值位于由空格分隔的两列中。如何在我的 cURL 命令中遍历所有这些值?

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

【问题讨论】:

    标签: bash unix curl jenkins


    【解决方案1】:

    在你的测试输入中使用了这个

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

    infile 包含您的数据的位置。

    输出:

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

    现在您已将它们存储在变量中,您可以将它们添加到您的 curl 命令中

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-18
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-10
      相关资源
      最近更新 更多