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 5976783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:16:38+00:00 2026-05-22T21:16:38+00:00

I used this ksh function for converting 1-Jan-2011 format to 1.1.2011. #!/bin/ksh ##—- function

  • 0

I used this ksh function for converting “1-Jan-2011” format to “1.1.2011.”

#!/bin/ksh

##---- function to convert 3 char month into numeric value ----------
convertDate()
{
    echo $1 | awk -F"-" '{print $1,$2,$3}' | read day mm yyyy ## split the date arg
    typeset -u mmm=`echo $mm` ## set month to uppercase
    typeset -u months=`cal $yyyy | grep "[A-Z][a-z][a-z]"` ## uppercase list of all months
    i=1 ## starting month
    for mon in $months; do ## loop thru month list
    ## if months match, set numeric month (add zero if needed); else increment month counter
    [[ "$mon" = "$mmm" ]] && typeset -xZ2 monthNum=$i || (( i += 1 ))
    done ## end loop
    echo $day.$monthNum.`echo $yyyy | cut -c3-` ## return all numeric date format ddmmyyyy
}

But I need to use this function with #!/bin/sh. So I tried rewriting it…

#!/bin/sh

##---- function to convert 3 char month into numeric value ----------
convertDate()
{
    echo $1 | awk -F"-" '{print $1,$2,$3}' | read day mm yyyy ## split the date arg
    echo $mm #IT SEEMS LIKE THE PROBLEM IS IN THE PREVIOUS LINE, BECAUSE THIS VARIABLE IS EMPTY IN #!/bin/sh, BUT IF YOU CHANGE IT TO #!/bin/ksh EVERYTHING SEEM TO BE FINE, THEN FUNCTION WORKS CORRECTLY.
    mmm=`echo $mm | tr '[a-z]' '[A-Z]'`
    months=`cal $yyyy | grep "[A-Z][a-z][a-z]" | tr '[a-z]' '[A-Z]'`
    i=1 ## starting month
    for mon in $months; do ## loop thru month list
    ## if months match, set numeric month (add zero if needed); else increment month counter
    if [ "$mon" = "$mmm" ]; then
        monthNum=`printf '%02d' $i`
    else
        i=`expr $i + 1`
    fi
    done ## end loop
    echo $day.$monthNum.`echo $yyyy | cut -c3-` ## return all numeric date format ddmmyyyy
}

convertDate "20-May-2010"

But it doesn’t work (read the UPPERCASE comment in the last script) 🙁

Help!

  • 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-05-22T21:16:39+00:00Added an answer on May 22, 2026 at 9:16 pm

    The problem is that whether the read command runs in a subshell due to the pipeline depends on exactly which shell /bin/sh is; you will get one behavior from bash and another from legacy UNIX (e.g. Solaris) /bin/sh. Use set instead.

    set -- `echo $1 | awk -F"-" '{print $1,$2,$3}'`
    

    although I would probably write

    oIFS="$IFS"
    IFS=-
    set -- $1
    IFS="$oIFS"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my project i used this below function public function createIconMenu():NativeMenu{ var iconMenu:NativeMenu =
I used this jquery each function and iterated my json data with it.... $.each(data.Results,
I used this code to get the particular column value using jquery.. $(#Grid td:first-child).click(function()
I used this code to read file. But fread function always return 0. What
I used this brilliant solution to convert a linq query to a datatable. But
I used this function to start a form: echo form_open('email/send'); and after viewing the
I used this function to animate the parent element of the link: $(.user-review-toggle).toggle(function(){ $(this).css(backgroundPosition,
I used this and it crashed on some system: char s[8192] I just need
I used this hash function for a while (got it from the internet). The
I used this guide on Apple's website to enable PHP on my computer but

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.