2010-06-09

Giving standard input to a program run in a shell script

I modified my "lock screen" bash script just now to also work when X isn't running -- that is, I'm on a virtual console or shelled into my machine.

The script as it was did this: use purple-remote to set my status to "away" (if it was "available" -- otherwise don't touch it), then run i3lock to lock the X screen, then switch the screen off to save power, then when i3lock exits restore my IM status if it was changed.

I added an if [ $DISPLAY ] test to branch for X and non-X, putting vlock in the place of the i3lock and xset commands for the non-X branch. It didn't like this, though -- vlock complained that it wasn't a virtual console.

In order to get it working all I had to do was redirect the script's standard input to vlock like this: vlock -a </dev/stdin.

No comments:

Post a Comment