0

I created a task manager for linux with shell script I need to refresh the task manager every 3 seconds I was thinking of using Timer function but got stuck

I have these functions written:

getnum
print_form
printinfo
move_user_cursor

I got these functions in to a main function such as:

init() {
 getnum
 clear
 print_form
 printinfo
 move_user_cursor
}

and my script ends like this:

init

while true:
 do
  :
done

How can I make my script get refreshed every 3 seconds?

init(){
  getnum
  clear
  print_form
  printinfo
  move_user_cursor
}

init
while true;
do
  :
done

I expect Timer function, or sleep command

jww
  • 97,681
  • 90
  • 411
  • 885
K.Paul
  • 25
  • 2
  • 1
    Use the `sleep` command. For example: `sleep 3s` – Daniel R. Livingston May 14 '19 at 16:45
  • You want this to happen asynchronously, without ending the `while true` loop? – Barmar May 14 '19 at 16:47
  • Is `:` a placeholder in your `while` loop, or is it really a loop that does nothing? – Barmar May 14 '19 at 16:47
  • 2
    Possible duplicate of [How to include a timer in Bash Scripting?](https://stackoverflow.com/q/1226094/608639), [Run command every second in Bash?](https://stackoverflow.com/q/9299704/608639), [Repeat a Unix command every x seconds forever](https://unix.stackexchange.com/q/10646), [Repeat a command every x interval of time in terminal?](https://askubuntu.com/q/430382), [Repeat command automatically in Linux](https://stackoverflow.com/q/13593771/608639), etc. – jww May 14 '19 at 17:32

1 Answers1

2

Replace

init
while true;
do
  :
done

with

while true;
do
  init
  sleep 3s
done
Cyrus
  • 84,225
  • 14
  • 89
  • 153