1

I use the below function in ksh to return the long value of date parts

function convert_date_to_long {
    long_date="${1}${2}${3}"

    return $long_date;
}

but the result i get is 209 when i pass the parameters 2015 02 25 .

How do i get the long value 20150225?

6
  • Why don't you do the same thing as you as here?
    – cuonglm
    Jan 19, 2016 at 12:48
  • i tried it . so instead of return i gave echo $long_date but when i call the $? to get the value it returns 0
    – xGen
    Jan 19, 2016 at 12:51
  • Yes, because the echo command success. What do you actually want?
    – cuonglm
    Jan 19, 2016 at 12:54
  • For me it is working as expected
    – Pandya
    Jan 19, 2016 at 12:55
  • My requirement is to return the above value 20150225. Using return command it used to work for smaller numbers. But not sure why it is not allowed for large values
    – xGen
    Jan 19, 2016 at 13:00

1 Answer 1

0

return sets the exit status of the function, and this is a number between 0 and 255. If the number is larger than that, you get its value mod 256, and 20150225 % 256 is 209.

To get a string as output from a function, the function should echo it, and then you can capture it in the caller with command substution.

function convert_date_to_long {
    echo "${1}${2}${3}"
}

some_var=$(convert_date_to_long 2015 02 25)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .