[英]Bash script: parsing string with a command without executing it
I have a script that parses an xml in bash. 我有一个脚本,可以解析bash中的xml。 I'm having a problem with one of the elements as it contains a string with some command inside of it: ie:
我的元素之一有问题,因为它包含一个字符串,其中包含一些命令:即:
/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 **"
How could I set that string into a variable (and print it) whithout executing the commands inside? 在不执行内部命令的情况下,如何将该字符串设置为变量(并打印)? I end up getting that printf in my output.
我最终在输出中得到该printf。
Thanks! 谢谢!
the code looks like this: 代码如下:
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
OUTPUT ON THE ECHO 回声输出
<![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 **"]]>
OUTPUT ON THE FILE 在文件上输出
<![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 **"]]>
This worked: 这工作:
writeLine="$writeLine"';'"$line" writeLine =“ $ writeLine”';'“ $ line”
... ...
echo "$writeLine" >> report.out 回声“ $ writeLine” >> report.out
Thanks all for your time! 感谢您的宝贵时间!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.