我在第14行和第16行有嵌套if語句的問題。它返回我的命令未找到錯誤,但我測試了該代碼的一部分,它可以在其他地方使用。Bash - 在if語句中找不到命令錯誤
#passing the argument page page.html
cat $1 | grep -o "wp-cli.org/commands/cache/\w*/\"" > temp.txt
#creating all pdf files
for i in $(cat temp.txt)
do
source=$(echo $i | grep -o -P "wp-cli.org/commands/cache/\w+")
dest=$(echo $i | grep -o -P "\w+/\"" | grep -o -P "\w+")
#echo $source $dest
wkhtmltopdf $source $dest".pdf"
pdfCount=$(ls *pdf | wc -l)
echo $pdfCount
if [ ! -f sample.pdf ]
then
if [$pdfCount -eq 1]
then
firstPdf=$dest".pdf"
fi
if [$pdfCount -eq 2]
then
pdfunite $firstPdf $dest".pdf" sample.pdf
fi
else
pdfunite $dest".pdf" oldsample.pdf sample.pdf
mv sample.pdf oldsample.pdf
fi
done
任何人都有一個想法嗎?謝謝...
你從哪裏學習寫這段代碼? – 123
我讀了一些書,但是很長一段時間我還沒有創建腳本,爲什麼? – Salvio
學會使用(並瞭解http://shellcheck.net的輸出)。作爲防禦性編程的問題,很少有你不想在變量周圍使用dbl-quotes的情況,所以''firstPdf''''''''''''''''''''' 2017'。祝你好運。 – shellter