I'm writing a script in which I pass the output of a function to less
, wait for some time, and then kill less
. All of this done inside a loop. This makes it look like less
is updated on the fly. This is my script:
#!/usr/bin/env bash
for i in {0..5}; do
echo $i | less -c &
pid=$!
sleep 2
kill $pid &>/dev/null
done
This works as expected, but the terminal kind of becomes unresponsive (keystrokes are not visible for instance) after this. What am I doing wrong?
EDIT: Okay, I think the way I asked the question was confusing. I'm trying to write a script which scrapes lyrics off a website according to the current song in music player. The way I want to do this, I'll keep this script running in a screen session, and I want it to auto-update every 30s or so. The finall script would look something like:
function get_lyrics()
{
# function which gets the lyrics based on current song
}
while true; do
song=$(get_lyrics)
echo "$song" | less -c &
pid=$!
sleep 30
kill $pid &>/dev/null
done
less &
sends it to the background.