Do math arithmetic on busybox sh

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|improve this question






















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














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.







share|improve this question






















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












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.







share|improve this question














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.









share|improve this question













share|improve this question




share|improve this question








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
















  • 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










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





share|improve this answer




















  • Appreciate your answer. But I ended up using awk. TOTSEC=`awk "BEGIN print $SEC+($MIN*60)"`
    – GeneCode
    Mar 23 at 2:50











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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






























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





share|improve this answer




















  • Appreciate your answer. But I ended up using awk. TOTSEC=`awk "BEGIN print $SEC+($MIN*60)"`
    – GeneCode
    Mar 23 at 2:50















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





share|improve this answer




















  • Appreciate your answer. But I ended up using awk. TOTSEC=`awk "BEGIN print $SEC+($MIN*60)"`
    – GeneCode
    Mar 23 at 2:50













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





share|improve this answer












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






share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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













 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay