How do i obtain the number of seconds my shell has been running?



  • Man page for bash.

    On the command line it show how long in seconds, you have been running the shell.

    $ echo $SECONDS
    

    This can be useful in bash shell scripts and one way of performing loops that are time dependant, In the shell script you can do one thing, wait for a number of seconds, hen do something else.

    sleep is just used to demo the delay between the seconds.

    #!/bin/bash
    
    sleep 5
    echo $SECONDS
    
    export SECONDS=0
    sleep 5
    echo $SECONDS
    

    Running the script.

    $ ./seconds.sh
    5
    5
    

Log in to reply
 

© Lightnetics 2024