0

I have string variables MIN and SEC (minute and seconds):

MIN="1"
SEC="34"

I want to do calculations on these:

TOTSEC = MIN*60 + SEC

I tried:

expr $SEC + $MIN * 60

Result:

expr: non-numeric argument

Let it be known I am running busybox on a custom microcomputer and so have no access to bash, bc, and that other solution provides.

  • You probably just need to escape the * i.e. expr $SEC + $MIN \* 60 – steeldriver Mar 23 '18 at 2:12
6

busybox uses ash, so you can use:

MIN=1 SEC=34 busybox sh -c 'echo "$(( MIN*60 + SEC ))"'
94

Or with expr:

MIN=1 SEC=34 busybox sh -c 'expr " $MIN" \* 60 + "$SEC"'
94
  • Appreciate your answer. But I ended up using awk. TOTSEC=`awk "BEGIN {print $SEC+($MIN*60)}"` – GeneCode Mar 23 '18 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.