We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,676 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

In return value Problem

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

3
Contributors
2
Replies
4 Days
Discussion Span
1 Year Ago
Last Updated
3
Views
Aamit
Posting Whiz
343 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
Skill Endorsements: 0

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

L7Sqr
Practically a Posting Shark
849 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7

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"
thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.5169 seconds using 2.68MB