我已經編寫了基於某個日期條件的清理活動腳本。但我得到一個錯誤。Bash - 語法錯誤:文件意外結束
#!/bin/bash
echo "Process Started"
Current_Date=`date +%Y-%m-%d`
echo "todays Date ==> $Current_Date"
fromDate=$1
toDate=$2
oldDate=`date --date="3 years ago" +%Y-%m-%d`
echo "Two Yrs Back Date ==> $oldDate"
if [ $toDate -le $oldDate ]
then
find . -type f -newermt $fromDate ! -newermt $toDate -exec truncate -s 0 {} \; && echo "truncated"
else
echo "todate should be less than three years"
fi
echo "Done"
得到的錯誤 - line 15: syntax error: unexpected end of file
雖然行15是不存在的腳本只有14行。此外,bash腳本運行良好,直到命令echo "Two Yrs Back Date ==> $oldDate"
。 之後它會在if
條件開始時給出錯誤。 只是想檢查我正在做的任何語法錯誤。
引用所有的變數。 – 123
bash腳本運行良好,直到命令'echo「Two Yrs Back Date ==> $ oldDate」'之後,它在if條件開始時給出錯誤。 – Sam
'bash -n yourscpript'說什麼?當你做'od -c yourscript'時,任何有趣的角色(\ r而不是\ n)? – Jens