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

Recommended Answers

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

Jump to Post

All 2 Replies

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

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"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.