1
我在CYGWIN中的shell腳本中運行上述命令時出現以下錯誤。`sed:-e表達式#1,字符1:未知命令:`,'`
錯誤:
sed: -e expression #1, char 1: unknown command: `,'
如果我跑在cmd命令:
$ sed -n "8937,8946 p" "/cygdrive/c/TEMP/temp_oracle/alert_cert1_copy.log" | egrep -e "ORA-|Shutting down"
它的工作原理確定 - 結果:
ORA-1623 signalled during: ALTER DATABASE DROP LOGFILE GROUP 1...
Shutting down database
注:8937
& 8946
是行號文本文件 - 它需要檢查模式。搜索必須位於這些行之間。
如果我從shell腳本運行命令 - 出現上述錯誤。
Shell腳本:
export alert_file="/cygdrive/c/TEMP/temp_oracle/alert_cert1_copy.log"
export alert_output="/cygdrive/c/cygwin64/home/alert_out.log"
function searchAlertByFilterLN() {
#err1=$(sed -n "${lastLineNum},${totLines} p" $alert_file | egrep -e "ORA-")
err1=$(sed -n "8937,8946 p" $alert_file | egrep -e "ORA-|Shutting down")
if [ -n "$err1" ]; then
echo -e "Errors found:" > $alert_output
echo ------------ >> $alert_output
sed -n "8937,8946 p" $alert_file | egrep -e "ORA-|Shutting down" >> $alert_output
echo "" >> $alert_output
echo "" >> $alert_output
echo -e "Check the details of the errors below. (Details means the surroundig lines of the error message only)" >> $alert_output
echo "-------------------------------------" >> $alert_output
sed -n "8937,8946 p" $alert_file | /usr/bin/egrep -A 5 -B 2 "ORA-|Shutting down" >> $alert_output
fi
}
searchAlertByFilterLN --
echo "function was executed"
至於!圍繞腳本變量
複製粘貼您的腳本的內容和你是如何運行腳本? – Inian
不要讓我們猜測,告訴你實際的腳本代碼失敗。我敢打賭,你正在使用'sed -n「$ startLineNo,$ endLineNo p」文件「或類似的名字,或者是拼寫錯誤,或者出於其他原因,一個或兩個都沒有值。你知道shell調試模式,用'set -vx'(和'set + vx'關閉)。這將向你顯示行被執行**,**變量被它們的值替換。祝你好運。 – shellter
此外,請閱讀http://stackoverflow.com/help/how-to-ask,http://stackoverflow.com/help/dont-ask,http://stackoverflow.com/help/mcve並採取[遊覽](http://stackoverflow.com/tour),然後在此處發佈更多Q.祝你好運。 – shellter