[英]Bash script: parsing string with a command without executing it
我有一個腳本,可以解析bash中的xml。 我的元素之一有問題,因為它包含一個字符串,其中包含一些命令:即:
/usr/bin/printf "%b" "***** MONITORING ***** \n\n Notification Type: Critical \n Host: &{INTERNETMANAGED_URL00.URL} \n Estado: &{INTERNETMANAGED_URL00.Status} \n Time: &{INTERNETMANAGED_URL00.Status_Timestamp} Format: cyymmddhhmmssttt \n Contact to:APPSRV "|/usr/bin/mail blabla@bla.com -c bllu@bluu.com -r "AAAAA" -s "** MONITORING - Server URL -Critical **"
在不執行內部命令的情況下,如何將該字符串設置為變量(並打印)? 我最終在輸出中得到該printf。
謝謝!
代碼如下:
while read line
do
if [[ $line == *"SITNAME"* ]] || [[ $line == *"TEXT"* ]] ; then
flag=true
fi
if [ $flag= 'true' ]; then
echo "$line"
writeLine=$writeLine';'"$line"
fi
done < file.text
echo $writeLine >> report.out
writeLine=""
flag=false
回聲輸出
<![CDATA[/usr/bin/printf "%b" "***** MONITORING ***** nn Notification Type: Critical n Host: &{INTERNETMANAGED_URL00.URL} n Stat: &{INTERNETMANAGED_URL00.Status} n Time: &{INTERNETMANAGED_URL00.Status_Timestamp} Format: cyymmddhhmmssttt n Contact to:APPSRV "|/usr/bin/mail mail@mail.com -r "MONITORING" -s "** MONITORING - Server URL -Critical **"]]>
在文件上輸出
<![CDATA[/usr/bin/printf "%b" "***** MONITORING file1.txt readme.txt file.xml script.sh nn Notification Type: Critical n Host: &{INTERNETMANAGED_URL00.URL} n Stat: &{INTERNETMANAGED_URL00.Status} n Time: &{INTERNETMANAGED_URL00.Status_Timestamp} Format: cyymmddhhmmssttt n Contact to:APPSRV "|/usr/bin/mail mail@mail.com -r "MONITORING" -s "** MONITORING - Server URL -Critical **"]]>
這工作:
writeLine =“ $ writeLine”';'“ $ line”
...
回聲“ $ writeLine” >> report.out
感謝您的寶貴時間!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.