Bash script function return value problem

Posted by Eedoh on Stack Overflow See other posts from Stack Overflow or by Eedoh
Published on 2010-12-27T10:43:40Z Indexed on 2010/12/27 10:54 UTC
Read the original article Hit count: 239

Filed under:
|
|
|
|

Hi to all.

Can anyone help me return the correct value from a bash script function?

Here's my function that should return first (and only) line of the file passed as an argument:

LOG_FILE_CREATION_TIME()
{
    return_value=`awk 'NR==1' $1`
    return return_value
}

And here's my call of that function in the other script:

LOG_FILE_CREATION_TIME "logfile"
timestamp=$?
echo "Timestamp = $timestamp"

I always get some random values with this code. If, for example, there's a value of 62772031 in the "logfile", I get

Timestamp = 255

as an output. For some other values in the file, I get other random values as a return value, never the correct one.

Any ideas?

© Stack Overflow or respective owner

Related posts about linux

Related posts about bash