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?

xGen
  • 653

1 Answers1

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)
Barmar
  • 9,927