On another list we were discussing features like the ability to close the 
netbook and have it continue to run.  Someone found an interesting script 
and I commented on that:


On Wed, 18 Nov 2009, Russell Horn wrote:

> Looks like this is scriptable to the extent that you can even turn off 
> the LCD but keep the machine running if you're playing music.
>
> http://forum.eeeuser.com/viewtopic.php?id=38393


Wow.  That is worth studying a bit.  There are lots of neat little tricks 
worked into that script.  I do a lot of scripting but I wouldn't have 
known how to detect all the different states of the machine (plugged in, 
etc.), so this part is awesome:

LID_STATE=`cat /proc/acpi/button/lid/LID/state | awk '{print $2 }'`
AC0_STATE=`cat /proc/acpi/ac_adapter/AC0/state | awk '{print $2 }'`
VGA_STATE=`xrandr --prop -display :0.0 | grep "VGA connected [0-9]" | wc -l`
LVDS_STATE=`xrandr --prop -display :0.0 | grep "LVDS connected [0-9]" | wc -l`

I guess the guy doesn't know that the backtick is being deprecated in 
sh/bash, so we are supposed to do it like this using "$()":

LID_STATE=$(cat /proc/acpi/button/lid/LID/state | awk '{print $2 }')

That dollar-sign trick is pretty great because it works with nesting while 
the backtick cannot.  His code is also an example of a bad use of "cat" 
because this works:

LID_STATE=$(awk '{print $2}' /proc/acpi/button/lid/LID/state)

So that's how I'll do it.  It looks like there is a world of interesting 
data in /proc/acpi


Different topic -- by the way, the other deprecation thing I have been 
trying to force myself to remember is to use "grep -E" instead of "egrep".

Mike