我有一个用Bash编写的自动化脚本。我需要从中执行一个perl脚本,并捕获/解析其输出的一个特定部分,并将其用作变量以完成bash脚本的任务。
例如:
echo "Creating database for "$custname
perl /home/dib/testing/addCustomer.cgi name=$custname prefix=$customerno
perl 脚本 "addCustomer.cgi" 将返回以下 JSON 输出:
Content-Type: application/json; charset=UTF-8
{
"recordcount" : 1,
"status" : "OK",
"statusText" : "Add Customer: 40:Testing",
"customer" : [
{
"address" : "",
"city" : "",
"country" : "US",
"description" : "",
"email" : "",
"endDate" : "0000-00-00 00:00:00",
"frontendurl" : "",
"phone" : "",
"prefix" : "testing",
"startDate" : "0000-00-00 00:00:00",
"state" : "",
"customerID" : "40",
"subscriberName" : "Testing",
"url" : "",
"zip" : ""
}
],
"timestamp" : 1559163419
}
我需要捕获的是 customerID 号,将其粘贴到变量中,并使用它来完成 bash 脚本。这样的事情可能吗?我总是看到解析或从 bash 传递到 perl,但不是相反。
将其附加到您的 Perl 命令中:
| sed 1d | jq -r '.customer[].customerID'
输出:
40
我假设有一个标题行。