notes/Raspberry Pi GPIO button press-tK88kQ9z.sh
#!/bin/bash


if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root"
   echo "Trying to restart with sudo"
   sudo $0 $@
   exit
fi

pin=23

#Enable GPIO23

echo $pin > /sys/class/gpio/export

#Set GPIO23 as input

echo in > /sys/class/gpio/gpio$pin/direction

clear
b=0
echo "Not Pressed"

while [ 1 ];
do
  v="$(cat /sys/class/gpio/gpio$pin/value)"
  if [ "$b" -ne "$v" ]
  then
    clear
    b=$v
    if [ "$b" -eq "0" ]
    then
      echo "Not Pressed"
    else
      echo "Pressed"
    fi
  fi

done

syntax highlighted by Code2HTML, v. 0.9.1