How to set a bash script to refresh the screen with variable values like TOP command?
To show the variable value I use:
echo "$var"
But it prints a new line, instead of I would like something that refresh the screen
How to achieve this?
答案 0 :(得分:2)
The easiest way is to just use watch
:
watch date
You can also just call clear
before each iteration. Here, all the output from clear
and any commands are collected as a form of double buffering to reduce flickering:
show_things() {
date
uname -a
echo "Your lucky number is $RANDOM"
}
while sleep 1
do
printf '%s\n' "$(clear; show_things)"
done