我的格式化打印语法错误在哪里?

问题描述 投票:0回答:1

我目前正在为我的一门课程做作业,我已经完成了大部分代码,但是当我运行它时,我收到此错误:

第 48 行:意外标记“%6.2f”附近存在语法错误

我现在已经解析了我的代码大约一千次,并且已经改变了一切,希望它能起作用,但我不知所措,所以我在这里问。

这是我的代码:

file="./homeOfficeData.dat"
totElec=0
totHeat=0
totTele=0
totMorInt=0
totRent=0
totCityTaxes=0
totIns=0
totRepMain=0
totDepr=0
totMonth=0

echo "---------------------------------------------------------------------------------------------------------------------------------------------------------"
printf "%82s" "HOME OFFICE EXPENSES"
printf "\n%92s" "Report Date $(date)"
printf "\n%85s\n" "Prepared by: **********"
echo "........................................................................................................................................................."
printf "%s %13s %9s %11s %19s %6s %12s %11s %18s %21s %17s\n" "Month" "Electricity" "Heating" "Telephone" "Mortgage Interest" "Rent" "City Taxes" "Home Ins." "Repairs & Maint." "Depreciation (7.5%)" "Total Per Month"
echo "........................................................................................................................................................."

while IFS=, read -r elec1 heat2 tele3 morInt4 rent5 cityTaxes6 ins7 repMain8; do
totElec=$(echo "$totElec+$elec1" | bc -l)
totHeat=$(echo "$totHeat+$heat2" | bc -l)
totTele=$(echo "$totTele+$tele3" | bc -l)
totMorInt=$(echo "$totMorInt+$mortInt4" | bc -l)
totRent=$(echo "$totRent+$rent5" | bc -l)
totCityTaxes=$(echo "$totCityTaxes+$cityTaxes6" | bc -l)
totIns=$(echo "$totIns+$ins7" | bc -l)
totRepMain=$(echo "$totRepMain+$repMain8" | bc -l)
dep9=$(echo "$elec1+heat2+tele3+morInt4+rent5+cityTaxes6+ins7+repMain8" | bc -l)
depreciationValue=$(echo "$dep9*7.5/100" | bc -l)
totMonth=$(echo "$elec1+heat2+tele3+mortInt4+rent5+cityTaxes6+ins7+repMain8+dep9" | bc -l)

printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "January" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "February" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "March" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "April" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "May" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "June" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "July" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "August" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "September" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "October" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "November" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f\n" "December" "$elec1" "$heat2" "$tele3" "$morInt4" "$rent5" "$cityTaxes6" "$ins7" "$repMain8"
done <"$file”
echo "........................................................................................................................................................."
printf "%s %6.2f %6.2f %6.2f %6.2f %7.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n" "Totals Paid" "$totElec" "$totHeat" "$totTele" "$totMorInt" "$totRent" "$totCityTaxes" "$totIns" "$totRepMain" "$depreciationValue" "$totMonth"

echo "Grand Total: $totMonth"
echo "Percentage: 8%           **This is the percentage of your home, exclusively used as the business office or space."
echo "Total Claim: $(echo "$totMonth*80/100");

此代码应该读取文件中以逗号分隔的数据,并将数据打印在列表中,同时进行算术得出一些结论。文件中的数据如下所示:

178.67,140.67,120.00,780.00,1200.00,456.78,680.90,800.00
211.00,146.00,130.00,780.00,1200.00,691.00,680.90,0.00
234.45,140.00,115.78,780.00,1200.00,559.00,680.90,0.00
280.78,136.00,124.67,780.00,1200.00,601.00,710.45,900.00
298.45,100.00,120.67,780.00,1300.00,425.56,710.45,456.78
320.90,55.00,131.00,780.00,1300.00,638.00,710.45,39.89
340.90,45.89,143.89,780.00,1300.00,732.56,710.45,127.67
350.89,50.34,189.78,780.00,1300.00,623.67,731.34,0.00
349.45,57.67,170.56,780.00,1350.00,578.32,731.34,245.67
290.90,65.67,150.44,780.00,1350.00,497.67,731.34,0.00
245.90,79.89,130.34,780.00,1350.00,501.45,750.00,0.00
210.56,120.99,141.56,780.00,1350.00,510.56,750.00,325.11

运行时,输出应该如下所示...

我很感谢任何可以帮助我的人,因为我在这里真的很烦恼。这位教授给出的每个示例都遵循我使用过的语法,但我只是找不到为什么会出现此错误。

bash shell formatting
1个回答
0
投票

查看语法突出显示。第46行

done <"$file”

这个角色
不是那个角色
"

done <"$file"

© www.soinside.com 2019 - 2024. All rights reserved.