简体   繁体   English

从具有多列的文件循环-BASH

[英]For loop from file with multiple columns-BASH

i have following text file (output.txt) 我有以下文本文件(output.txt)

TECH-746 TECH 10400
TECH-747 TECH 10400

i need to read all columns and pass it to 3 variables and then submit it to curl command. 我需要读取所有列并将其传递给3个变量,然后将其提交给curl命令。 While read simple won't work with curl (don't know why) so i need to use for loop (it works with curl), can i use one for loop or need to nest multiple ones 虽然简单阅读不适用于curl(不知道为什么),所以我需要使用for loop (适用于curl),我可以使用一个for循环还是需要嵌套多个

for project in `cat output.txt`; do
echo $project
curl -D- -u user:pass -X POST --data "{\"fields\":{\"project\":{\"key\":\"TECH\"},\"parent\":{\"key\":\"$project\"},\"summary\":\"test",\"description\":\"test.\",\"issuetype\":{\"name\":\"Sub-task\"}}}" -H "Content-Type:application/json" --silent https://jira.company.com/rest/api/latest/issue/ >/dev/null

code above works, so i just want to "extend" to to include all other columns in file 上面的代码有效,所以我只想“扩展”以包括文件中的所有其他列

while read can pull a line into distinct variables. while read可以将一行插入不同的变量中。

while read project col2 col3
do
  curl -D- -u user:pass -X POST --data "{\"fields\":{\"project\":{\"key\":\"TECH\"},\"parent\":{\"key\":\"$project\"},\"summary\":\"test",\"description\":\"test.\",\"issuetype\":{\"name\":\"Sub-task\"}}}" -H "Content-Type:application/json" --silent https://jira.company.com/rest/api/latest/issue/ >/dev/null
done < sourcefile.txt

EDIT: The curl command also misses escaping one quote, compare the two lines below, the first one is the original, the second one is the one I've corrected. 编辑: curl命令也错过了转义一个引号,比较下面的两行,第一行是原始行,第二行是我已更正的行。

curl -D- -u user:pass -X POST --data "{\"fields\":{\"project\":{\"key\":\"TECH\"},\"parent\":{\"key\":\"$project\"},\"summary\":\"test",\"description\":\"test.\",\"issuetype\":{\"name\":\"Sub-task\"}}}" -H "Content-Type:application/json" --silent https://jira.company.com/rest/api/latest/issue/ >/dev/null
curl -D- -u user:pass -X POST --data "{\"fields\":{\"project\":{\"key\":\"TECH\"},\"parent\":{\"key\":\"$project\"},\"summary\":\"test\",\"description\":\"test.\",\"issuetype\":{\"name\":\"Sub-task\"}}}" -H "Content-Type:application/json" --silent https://jira.company.com/rest/api/latest/issue/ >/dev/null

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

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