Score:0

Bash sleep function

sd flag

With the bash sleep function, can you program sleep in a bash script to sleep 5 seconds, then 500 seconds then 1000 and rotate to back to 5,500,1000? Thanks, my current script below.

xdotool getmouselocation
sudo apt-get install xdotool

``
#!/bin/bash
while [ 1 ]; do
  xdotool mousemove XXX YYY click 1 &
  sleep 5
done

FedKad avatar
cn flag
As a simple solution, you can put the three `sleep` statements one after another, and then all of them into a loop.
cn flag
Technically, bash does not have a "sleep function". [`sleep`](https://manpages.ubuntu.com/manpages/focal/en/man1/sleep.1.html) is a separate executable
Score:2
cn flag

I don't understand why you would want to do this, but

for rotations in 1 2; do
  for duration in 5 500 1000; do
    sleep $duration
  done
done
Score:1
hr flag

sleep is an external command - not a bash function.

To cycle indefinitely through a set of values, you can use an array with an index derived using modulo arithmetic. Ex.

#!/bin/bash

s=(5 500 1000)

i=0
while : ; do
  # some commands
  sleep "${s[i]}"
  i=$((++i%3))
done
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.