I am learning Raspberry Pi and trying to use code to read my CPU temperature and save it to a file with a bash script. The code is here:
#!/bin/bash
echo ""
cpu=$( $(/opt/vc/bin/vcgencmd measure_temp)"
far=$((cpu/1000))
far2=$((far*9))
far3=$((far2/5))
far4=$((far3+32))
echo "CPU => $((cpu/1000))' C or $((far4))' F"
echo ""
echo "Pi temp $far4 degrees F" > /var/www/html/pitemp.txt
Here is the error:
$ sudo chmod +x checkTemp.sh
$ ./checkTemp.sh
./checkTemp.sh: line 10: unexpected EOF while looking for matching `"'
./checkTemp.sh: line 11: syntax error: unexpected end of file
$ _
Why is it wrong? Here is the instruction I follow.
cpu=line from it verbatim -- that's wrong too. (c) It does not explain that you need to make the script executable.shellcheck.net. You can validate any shell script in detail -- either online, or download the tool. Highly recommended.