sparks
July 14, 2010, 5:22am
1
Hi all,
i am facing the error "expr: non-numeric argument" when i use the expr command.
Following is the expression which i want to execute
HR=$(echo `date +%H`)
MIN=$(echo `date +%M`)
TOT_MIN=`expr "$HR" \* 60+$MIN` | bc
echo $TOT_MIN
Here I am being reported with the error expr: non-numeric argument.
when i use bc i get the standard parse error. :o
Please help me how to get rid of these errors.
Thanks in advance!!!
HR=$(echo `date +%H`)
MIN=$(echo `date +%M`)
TOT_MIN=`expr "$HR" \* 60 + $MIN | bc`
echo $TOT_MIN
The closing backtick must be at the end of the line. Replace this:
TOT_MIN=`expr "$HR" \* 60+$MIN` | bc
with:
TOT_MIN=`expr $HR \* 60 + $MIN | bc`
Scott
July 14, 2010, 5:54am
4
Not if you do this (as I just did by accident!)
TOT_MIN=`expr "$HR \* 60+$MIN` | bc
There's no floating point stuff here, so I would get rid of bc and expr:
TOT_MIN=$(($HR * 60 + $MIN))
clx
July 14, 2010, 6:06am
5
typeset is also an alternative,
typeset -i HR MIN TOT_MIN
HR=$(date +%H)
MIN=$(date +%M)
TOT_MIN=$HR*60+$MIN
sparks
July 14, 2010, 8:25am
7
Thanks everybody.. It helped