Script to toggle touchpad This sequence properly shows whether the TouchpadOff option for synclient is on or not (outputs either a 0 or a 1):

synclient | grep 'TouchpadOff' | tail -n 1 | awk '{print substr($3, 1)}'


Trying to make a keyboard shortcut to toggle the touchpad with a basic script based on that line, I wrote this:

#!/bin/bash

PADOFF=$(synclient | grep 'TouchpadOff' | tail -n 1 | awk '{print substr($3, 1)}')
if [ "$PADOFF" == "0" ]
then
    synclient TouchpadOff=1
else
    synclient TouchpadOff=0
fi.
I don't understand the purpose of substr($3, 1) — isn't that the same as $3?

AWK alone can do the work of grep, tail, and negation.  I would write it this way:

synclient TouchpadOff=$(synclient | awk '/TouchpadOff/ { off=int($3) }
                                         END           { print !off }')