linuxshellunix

Shell Scripting: execute echo statements with a time delay


Is there any way I could run several echo statements one after the other with a delay?

For example:

The first statement will be:

echo Hello1

after 1/2 second, run the Second echo statement:

echo Hello2

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


Solution

  • Perhaps you would like to use sleep <number of seconds> Like sleep 60 to wait for a minute.

    eg. run from commandline

    $ 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'