1.11M Members

In return value Problem

 
0
 

Hi,

check_time()
{
 fileName=$myFileName
newTime=$line
newtimeaccess="date --date \"$newTime 6 hour\" '+%Y-%m-%d %H:%M:%S'"
newtimeaccess=`echo $newtimeaccess | sh`
strnewtime=$(date -d "$newtimeaccess" +%s)
systime=$(date  +%s)
if [ $systime -le $strnewtime ]
then
        return "$fileName__0";
else
        return "$fileName__1";
fi
}

value=`check_time "$myFileName $line"`
##$myFileName -- file name and $line -- time of file

echo $value;

It giving error return: : numeric argument required
How to solve It

 
0
 

You can not return a string. You must return a numeric value. So changing "$fileName__0" to something like 0 would work.

 
0
 

You can of course "return" a string like this.. which is not really returning and it forces you to ensure that there are no unwanted `echo`s in the function.. but it works.. :)

#!/bin/bash

function gimme_string() {
    echo "returned string"
}

my_string=`gimme_string`

echo "String I got is: $my_string"
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article