1

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.

1
  • You probably just need to escape the * i.e. expr $SEC + $MIN \* 60 Commented Mar 23, 2018 at 2:12

1 Answer 1

11

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
1
  • 2
    Appreciate your answer. But I ended up using awk. TOTSEC=`awk "BEGIN {print $SEC+($MIN*60)}"` Commented Mar 23, 2018 at 2:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.