#!/bin/bash #store current state on start last_state=`cat /proc/acpi/battery/BAT1/state` #lets write it to console echo "current_state: $last_state" #keep looking for changes using an infinite loop while true do state=`cat /proc/acpi/battery/BAT1/state` if [[ "$state" == "$last_state" ]]; then echo "state not changed don't do anything" else echo "state changed to $state , do something now" #update last state last_state=`echo $state` fi #just wait a little to avoid high cpu load sleep 5 done