Changes

Bash Shell Script Examples

1,092 bytes added, 18:59, 3 June 2019
The following lines were added (+) and removed (-):
===Stopwatch=== <nowiki>BEGIN=$(date +%s)</nowiki> <nowiki></nowiki> <nowiki>echo Starting Stopwatch...</nowiki> <nowiki>echo Press Q to exit.</nowiki> <nowiki></nowiki> <nowiki>while true; do</nowiki> <nowiki>    NOW=$(date +%s)</nowiki> <nowiki>    let DIFF=$(($NOW - $BEGIN))</nowiki> <nowiki>    let MINS=$(($DIFF / 60))</nowiki> <nowiki>    let SECS=$(($DIFF % 60))</nowiki> <nowiki>    let HOURS=$(($DIFF / 3600))</nowiki> <nowiki>    let DAYS=$(($DIFF / 86400))</nowiki> <nowiki></nowiki> <nowiki>    # \r  is a "carriage return" - returns cursor to start of line</nowiki> <nowiki>    printf "\r%3d Days, %02d:%02d:%02d" $DAYS $HOURS $MINS $SECS</nowiki> <nowiki></nowiki> <nowiki># In the following line -t for timeout, -N for just 1 character</nowiki> <nowiki>    read -t 0.25 -N 1 input</nowiki> <nowiki>    if [[ $input = "q" ]] || [[ $input = "Q" ]]; then</nowiki> <nowiki># The following line is for the prompt to appear on a new line.</nowiki> <nowiki>        echo</nowiki> <nowiki>        break </nowiki> <nowiki>    fi</nowiki> <nowiki>done</nowiki>
Bureaucrat, administrator
16,192
edits