Minor change to firstbootupdate

I’ve just been through an SD card failure (it went read-only luckily) and while building as new one and manually recovering files I came across this minor quoting issue in emonpi/firstbootupdate:

button="$(sudo cat /sys/class/gpio/gpio23/value)"

-if [ ! -s /home/pi/data/emonpiupdate.log ] || [ $button == 1 ]; then
+if [ ! -s /home/pi/data/emonpiupdate.log ] || [ “$button” == 1 ]; then
echo “First Boot Update…”
printf “Checking internet connectivity…wait 30s\n”
sleep 30

Without quotes the shell barfs.

Thanks, been fixed:

1 Like

Bash variables are subject to WordSplitting and pathname expansion.
So it’s always a good idea to double quote them.

An alternative is to use [[ instead of [
From The Bash Pitfalls web page

You don’t need to quote variable references on the left-hand side of = in [[ ]] because they don’t undergo word splitting or globbing,

The site at the link above is loaded with lots of info about avoiding common Bash scripting pitfalls.

The Advanced Bash Scripting Guide is also worth a look.

1 Like