Do math arithmetic on busybox sh
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
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.
shell busybox
add a comment |Â
up vote
0
down vote
favorite
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.
shell busybox
You probably just need to escape the*
i.e.expr $SEC + $MIN * 60
â steeldriver
Mar 23 at 2:12
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
shell busybox
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.
shell busybox
edited Mar 23 at 2:09
cuonglm
97.2k21185278
97.2k21185278
asked Mar 23 at 1:57
GeneCode
658
658
You probably just need to escape the*
i.e.expr $SEC + $MIN * 60
â steeldriver
Mar 23 at 2:12
add a comment |Â
You probably just need to escape the*
i.e.expr $SEC + $MIN * 60
â steeldriver
Mar 23 at 2:12
You probably just need to escape the
*
i.e. expr $SEC + $MIN * 60
â steeldriver
Mar 23 at 2:12
You probably just need to escape the
*
i.e. expr $SEC + $MIN * 60
â steeldriver
Mar 23 at 2:12
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
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 at 2:50
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
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 at 2:50
add a comment |Â
up vote
5
down vote
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 at 2:50
add a comment |Â
up vote
5
down vote
up vote
5
down vote
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
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
answered Mar 23 at 2:12
cuonglm
97.2k21185278
97.2k21185278
Appreciate your answer. But I ended up using awk. TOTSEC=`awk "BEGIN print $SEC+($MIN*60)"`
â GeneCode
Mar 23 at 2:50
add a comment |Â
Appreciate your answer. But I ended up using awk. TOTSEC=`awk "BEGIN print $SEC+($MIN*60)"`
â GeneCode
Mar 23 at 2:50
Appreciate your answer. But I ended up using awk. TOTSEC=`awk "BEGIN print $SEC+($MIN*60)"`
â GeneCode
Mar 23 at 2:50
Appreciate your answer. But I ended up using awk. TOTSEC=`awk "BEGIN print $SEC+($MIN*60)"`
â GeneCode
Mar 23 at 2:50
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f432979%2fdo-math-arithmetic-on-busybox-sh%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You probably just need to escape the
*
i.e.expr $SEC + $MIN * 60
â steeldriver
Mar 23 at 2:12