我在第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