我有一個解析bash中的xml的腳本。我遇到的要素之一的問題,因爲它包含了它裏面的一些命令字符串: 即:Bash腳本:使用命令解析字符串而不執行它
/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 [email protected] -c [email protected] -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 [email protected] -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 [email protected] -r "MONITORING" -s "** MONITORING - Server URL -Critical **"]]>
你的bash代碼是什麼樣的?通常,只讀文本並將其分配給變量不應該執行任何命令。 – chepner 2013-03-08 14:01:02
我用一些代碼編輯了問題。謝謝! – TheMadCapLaughs27 2013-03-08 14:12:31
該代碼中的任何內容都不會執行從'file.txt'中讀取的命令。是否僅包含包含「SITNAME」或「TEXT」的行或包含「SITNAME」或「TEXT」的行之後的每行? – chepner 2013-03-08 14:20:59