Results 1 to 2 of 2

Thread: seelct case based on current time

  1. #1
    Join Date
    Aug 2013
    Beans
    37

    seelct case based on current time

    HI Guys im tring to write a bash sccript which will give me the time of the next us from my local stop

    i have a list of times as below

    0735
    0805
    0835
    0905
    0935
    0950
    1020
    1050
    1120
    1150
    1220
    1250
    1320
    1350
    1420
    1450
    1520
    1550
    1620
    1650
    1650
    1720
    1800
    1840
    1922
    1942
    2002
    2022
    2102
    but have no dea how to do thia using a select case of if then statment can any one give me a heads up ?

    any help would be appreciated

    Pete

  2. #2
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: seelct case based on current time

    here's one way using an if statement and storing the times in a file

    Code:
    #!/bin/sh
    
    now="$(date +'%H%M')";
    for time in $(cat times.list);
    do
     if [ "$now" -lt "$time" ]; then
       echo $time;
       exit 0;
     fi
    done;
    echo You missed the last bus
    exit 1;

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •