Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8942829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:37:06+00:00 2026-06-15T11:37:06+00:00

Consider the below PSUEDO-CODE : #!/bin/ksh rangeStartTime_hr=13 rangeStartTime_min=56 rangeEndTime_hr=15 rangeEndTime_min=05 getCurrentMinute() { return `date

  • 0

Consider the below PSUEDO-CODE:

#!/bin/ksh

rangeStartTime_hr=13
rangeStartTime_min=56
rangeEndTime_hr=15
rangeEndTime_min=05


getCurrentMinute() {
    return `date +%M  | sed -e 's/0*//'`; 
    # Used sed to remove the padded 0 on the left. On successfully find&replacing 
    # the first match it returns the resultant string.
    # date command does not provide minutes in long integer format, on Solaris.
}

getCurrentHour() {
    return `date +%l`; # %l hour ( 1..12)
}

checkIfWithinRange() {
    if [[ getCurrentHour -ge $rangeStartTime_hr &&  
          getCurrentMinute -ge $rangeStartTime_min ]]; then
    # Ahead of start time.
        if [[  getCurrentHour -le $rangeEndTime_hr && 
                   getCurrentMinute -le $rangeEndTime_min]]; then
            # Within the time range.
            return 0;
        else
            return 1;
        fi
    else 
        return 1;   
    fi
}

Is there a better way of implementing checkIfWithinRange()? Are there any inbuilt functions in UNIX that make it easier to do the above? I am new to korn scripting and would appreciate your inputs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:37:07+00:00Added an answer on June 15, 2026 at 11:37 am

    The return command is used to return an exit status, not an arbitrary string. This is unlike many other languages. You use stdout to pass data:

    getCurrentMinute() {
        date +%M  | sed -e 's/^0//' 
        # make sure sed only removes zero from the beginning of the line
        # in the case of "00" don't be too greedy so only remove one 0
    }
    

    Also, you need more syntax to invoke the function. Currently you are comparing the literal string "getCurrentMinute" in the if condition

    if [[ $(getCurrentMinute) -ge $rangeStartTime_min && ...
    

    I would do if a bit differently

    start=13:56
    end=15:05
    
    checkIfWithinRange() {
        current=$(date +%H:%M) # Get's the current time in the format 05:18
        [[ ($start = $current || $start < $current) && ($current = $end || $current < $end) ]] 
    }
    
    if checkIfWithinRange; then
        do something
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the code below, private void Convert_Click(Object sender, RoutedEventArgs e) { string[] strCmdLineParams =
Consider the code below. I don't understand why my GCC compiler does not try
Consider below code: template<typename T> void f(T a[]) { if(sizeof(T) > 1) for(...)a[i] =
Consider below functions f(int a[]) { ///CODE for for if(a[i] > 0) //change i
I want to determine which attribute to look-up dynamicaly, Consider below python code: def
Consider the below code to save data in array, arr[]['name'] = 'hello'; arr[]['value'] =
Consider the below C++ code class B; class A{ private: B* mB; }; class
Please consider the below piece of code: HashSet hs = new HashSet(); hs.add(hi); --
Consider the code below XmlSerializer serializer = new XmlSerializer(typeof(Invoice)); using (TextWriter writer = new
Consider this code below: <a href="javascript:void(-1)" id="a1">a1</a> <a href="javascript:void(-1)" id="a2">a2</a> <script type="text/javascript"> var buttons

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.