I have a simple question. I know that shell scripts are slow/ineffective when it comes to recursion and looping.
Generally, is it possible to read the input continuously instead of having to loop the read/”grab” part of the code, for instances when the input is continual and in plenty( a kind of EVENT DRIVEN scenario ).
For example,,
I use fedora16(gnome3.2) and for reasons unknown the capslock notification is missing. I own a netbook and don’t have the “luxury” of indicator leds. So I’ve decided to write a shell script to notify me when the capslock key is pressed. I figured out a way to know the key state.
xset -q | grep Caps | awk '{print $4}'
that would give me “on”/”off” as the output. I can like have the loop to execute every one second(or less) but that would be a very crude way of doing it.
What you wrote is event-driven.
xset -qproduces some output, which only at that point (i.e. when it’s produced) is consumed bygrep. At that point,grepmight produce some output (only if it matches Caps) and only in that case willawkprocess something.The problem here is not bash – the “problem” is
xset -q. It was not designed to continuously give you output. It was designed as a one-shot output command.To touch the other part of the question – if you actually just need an indicator, look here:
An excellent source of all sorts of indicators. One of them is Keylock indicator (search the above page to see more info):
The above link is from askubuntu.com, i.e. it’s Ubuntu-centric, but the above seems to be available for Fedora, too:
From the above thread (this post by fewt):
Hope this helps.