expr: non-numeric argument

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!!! :slight_smile:

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`

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))

typeset is also an alternative,

typeset -i HR MIN TOT_MIN
HR=$(date +%H)
MIN=$(date +%M)
TOT_MIN=$HR*60+$MIN

Good point, Thanks!

Thanks everybody.. It helped :slight_smile: