[英]Bash Script with a loop of 2 variables
I'm having some hard time to work this one out. 我很难解决这个问题。 I need to feed GITLAP API with issues that are created based on a file that i have. 我需要向GITLAP API提供基于我拥有的文件创建的问题。 Normally the output of the file is the following: 通常,文件的输出如下:
Microsoft xxx xxxxx - Remote Code Execution xxxxxx- April 2018 xxxxx Updates Red Hat Enterprise xxxx - java-1.8.0-xxxxx Multiple xxxxxxx- RHSA-xxxxxx Microsoft xxx xxxxx-远程执行代码xxxxxx- 2018年4月xxxxx更新Red Hat Enterprise xxxx-java-1.8.0-xxxxx多个xxxxxxx- RHSA-xxxxxx
So far so good, I already deal with this the following way: 到目前为止,我已经通过以下方式处理了此问题:
while read in; do
curl --request POST --header "PRIVATE-TOKEN: xxxxxxxxxxxxx" https://gitlab.com/api/v3/projects/xxxxxx/issues?title="$in";
done < ~/input_file
The problem is now that i need to add a second variable to this because i need to introduce a description on each issue and now my input file change for the following: 现在的问题是,我需要为此添加第二个变量,因为我需要对每个问题进行描述,并且现在我的输入文件将更改为以下内容:
Microsoft Malware Protection - Remote Code Execution Vulnerability - April 2018 Security Updates 40697 Microsoft恶意软件保护-远程执行代码漏洞-2018年4月安全更新40697
Red Hat Enterprise Linux 6 - java-1.8.0-openjdk Multiple Vulnerabilities - RHSA-2018:1188 40861 红帽企业版Linux 6-java-1.8.0-openjdk多个漏洞-RHSA -2018:1188 40861
I would like to construct something like this: 我想构造这样的东西:
while read in;
curl --request POST --header "PRIVATE-TOKEN: xxxxxxxxxxx" "https://gitlab.com/api/v4/projects/xxxxx/issues?title=$in&description=https://myspecialink.com/portal/notifications/show/$id";
done < ~/input_file
for example: 例如:
$in
: must be everything except the bold number that i signalize above. $in
:必须是我上面表示的粗体数字以外的所有内容。 $id
: must be only the numbers in bold above. $id
:只能是上面的粗体数字。 Can someone help me on point me the best way of achieve this? 有人可以帮我指出实现这一目标的最佳方法吗?
Use bash parameter expansion operators to split the input. 使用bash 参数扩展运算符拆分输入。
while read in; do
id=${in##* } # Remove everything up to last space
in=${in% *} # Remove everything from last space
curl --request POST --header "PRIVATE-TOKEN: xxxxxxxxxxx" "https://gitlab.com/api/v4/projects/xxxxx/issues?title=$in&description=https://myspecialink.com/portal/notifications/show/$id";
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.