[英]How to print each element of Multi-line String Parameter by bash shell in Jenkins Job
當我想在詹金斯工作中使用多行字符串參數時 ,這很奇怪。 參數名稱為PRS_INFO
,其默認文本為:
PT54321:file xxx not exit
PT74231:xxx reboot
運行此作業后,參數設置為環境:
PRS_INFO PT54321:file xxx not exit>PT74231:xxx reboot
但是當我想使用bash shell代碼逐行打印它時:
set -x
IFS_OLD=$IFS
IFS='>'
for i in $PRONTO_INFO; do
echo $i
done
IFS=$IFS_OLD
它在控制台中打印日志:
+ IFS_OLD='
'
+ IFS='>'
+ for i in '$PRS_INFO'
+ echo 'PT54321:file xxx not exit
PT74231:xxx reboot'
PT54321:file xxx not exit
PT74231:xxx reboot
+ IFS='
為什么只將echo
調用一次以打印所有行,而不是兩次調用以打印兩行?
PS。 Jenkins 2.32.3是我們使用的Jenkins版本。
您的PRS_INFO
變量中似乎沒有>
字符;
嘗試:
set -x
OLD_IFS="$IFS"
IFS=$'\n'
for line in $PRS_INFO; do
echo "$line"
done
IFS="$OLD_IFS"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.