Bash: How to make short delay? Bash: How to make short delay? bash bash

Bash: How to make short delay?


I don't know what version this was implemented in, but my version of sleep (v6.12) accepts decimals. sleep 0.5 works.

If yours is too old for that, a short python or C program would probably be your only solution.


SunOS (Solaris) probably doesn't have the GNU tools installed by default. You might consider installing them. It's also possible that they're already installed in your system, perhaps in some directory that isn't in your default $PATH. GNU sleep is part of the coreutils package.

If you have Perl, then this:

perl -MTime::HiRes -e 'Time::HiRes::usleep 500000'

should sleep for 500000 microseconds (0.5 second) -- but the overhead of invoking perl is substantial.

For minimal overhead, I'd write a small C program that calls usleep() or nanosleep(). Note that usleep() might not handle intervals greater than 1 second.


Write this to "usleep.c"

#include <unistd.h>#include <stdlib.h>int main(int argc, char **argv) {    usleep( atol( argv[1] ) );}

And type

make usleep./usleep 1000000