I’m currently working on an assignment for one of my classes and I have a bulk of the code finished but when I run it I’m getting this error:
line 48: syntax error near unexpected token `%6.2f’
I’ve parsed through my code about a thousand times now and have switched things around in hopes it’ll work, but I’m at a loss so I’m asking here.
This is my code:
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");
This code is supposed to read data separated by commas in a file and print the data in a columned table, while doing arithmetic to come to a few conclusions. The data in the file looks like this:
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
And when run, the output should look like this…
I appreciate anyone that can help me out because I’m seriously pulling my hair out here. Every example this professor has given follows the syntax I’ve used and I just cannot find why I’m getting this error.
>Solution :
Look at syntax highlighting. line 46 done <"$file”
This character ”is not that character "
done <"$file"
