Shell Scripting: Delayed Execution of Echo Statements

Is there any way to run multiple echo statements one after the other with a delay?

For example:

The first statement would be:

echo Hello1

      

after 1/2 second, run the second echo expression:

echo Hello2

      

Likewise, is it possible to run multiple statements one after the other with a time delay without printing all the echoes at once?

+3


source to share


3 answers


Perhaps you would like to use sleep <number of seconds>

For example sleep 60

to wait a minute.

eg. run from command line

$echo 'hello1'; sleep 2; echo 'hello2'



or in a bash script file (myscript.sh)

#!/bin/bash
echo 'hello1'
sleep 2
echo 'hello2 after 2 seconds'
sleep 2
echo 'hello3 after 2 seconds'

      

+4


source


echo Hello1
usleep 500000 # sleep 500,000 microseconds
echo Hello2

      



The command usleep(1)

is part of initscripts

a Fedora package .

+1


source


for i in `echo 'hello1 hello2 hello3" `; do echo $ i; sleep 2; done

0


source







All Articles