1個
這個問題已經在這裡有了答案:
從CYGWIN中的shell腳本運行上述命令時,出現以下錯誤。
錯誤:
sed:-e表達式#1,字符1:未知命令:`,'
如果我在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
注意:89378946是文本文件中的行號-需要在其中檢查模式。搜索必須在這些行之間。
如果我從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"
帶著敬意!

三方標記為重複 bash 9月30日在5:31

這個問題已經問過了,已經有了答案。如果這些答案不能完全解決您的問題,請提出一個新問題
1個
在腳本中的變量周圍使用正確的雙引號,以避免shell誤解您的正斜杠(/),換行符和單詞拆分。您的腳本中使用的所有變量都丟失了它。
您的腳本的更正版本應類似於
 #!/bin/bash

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 --