拆分具有特殊字符的数组元素

我想编写一个bash脚本(如果脚本是python的话,会更好),它执行一个Perl脚本( https://github.com/MangeshBiradar/Check_mk/blob/master/check_jenkins_jobs.pl )。 它是Perl脚本输出的输出:

 CRITICAL ~ First_run ~ Build stability: 3 out of the last 4 builds failed. ~ 25 CRITICAL ~ Mangesh_Testing ~ Build stability: All recent builds failed. ~ 0 CRITICAL ~ MKS_Integrity ~ Build stability: All recent builds failed. ~ 0 OK ~ MKS_TEST ~ Build stability: No recent builds failed. ~ 100 CRITICAL ~ Rest_api_testing ~ ~ no score CRITICAL ~ Second_job ~ ~ no score OK ~ Team_test ~ Build stability: No recent builds failed. ~ 100 OK ~ test ~ Build stability: No recent builds failed. ~ 100 CRITICAL ~ TEST_1 ~ Build stability: 2 out of the last 3 builds failed. ~ 33 OK ~ Update_Outlook ~ Build stability: No recent builds failed. ~ 100 

现在我有一个任务被添加到bash/python脚本中来parsingPerl脚本的输出。 根据parsing输出中的第一个字段(CRITICAL,OK),我想返回适当的值为CRITICAL返回2,为OK返回0等等。有什么办法可以实现这一点?

改变你的循环有点:

 for line in "${array[@]}" do OIFS=$IFS # store old IFS in buffer IFS='~' # set IFS to '-' for i in $line do echo $i done IFS=$OIFS done