while loop comparing two numbers from a string

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












I'm trying to create a simple bash script to run through a loop until size1=size2



I have a variable that I'm trying to extract size1 and size2



strvar=Size: 367.3 MiB/367.3 MiB Time: 2.04



can I use parameter expansion to extract just the numbers on each side of the "/" and split into two variables (size1,size2)? It's ok if the MiB stays as long as I can evaluate if size1 is the same as size2.



the variable $strvar is the output from a command. I use strvar=$(command | grep Size) to get it.










share|improve this question























  • Where does the string come from and why do you have it in a variable? If it's the output of a program, then the check could be done directly in a pipeline, reading from that program, depending on what it is you'd like to achieve.
    – Kusalananda
    Dec 7 at 23:18















up vote
-1
down vote

favorite












I'm trying to create a simple bash script to run through a loop until size1=size2



I have a variable that I'm trying to extract size1 and size2



strvar=Size: 367.3 MiB/367.3 MiB Time: 2.04



can I use parameter expansion to extract just the numbers on each side of the "/" and split into two variables (size1,size2)? It's ok if the MiB stays as long as I can evaluate if size1 is the same as size2.



the variable $strvar is the output from a command. I use strvar=$(command | grep Size) to get it.










share|improve this question























  • Where does the string come from and why do you have it in a variable? If it's the output of a program, then the check could be done directly in a pipeline, reading from that program, depending on what it is you'd like to achieve.
    – Kusalananda
    Dec 7 at 23:18













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I'm trying to create a simple bash script to run through a loop until size1=size2



I have a variable that I'm trying to extract size1 and size2



strvar=Size: 367.3 MiB/367.3 MiB Time: 2.04



can I use parameter expansion to extract just the numbers on each side of the "/" and split into two variables (size1,size2)? It's ok if the MiB stays as long as I can evaluate if size1 is the same as size2.



the variable $strvar is the output from a command. I use strvar=$(command | grep Size) to get it.










share|improve this question















I'm trying to create a simple bash script to run through a loop until size1=size2



I have a variable that I'm trying to extract size1 and size2



strvar=Size: 367.3 MiB/367.3 MiB Time: 2.04



can I use parameter expansion to extract just the numbers on each side of the "/" and split into two variables (size1,size2)? It's ok if the MiB stays as long as I can evaluate if size1 is the same as size2.



the variable $strvar is the output from a command. I use strvar=$(command | grep Size) to get it.







bash shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 8 at 12:42









RudiC

3,9541312




3,9541312










asked Dec 7 at 23:14









Bender

1




1











  • Where does the string come from and why do you have it in a variable? If it's the output of a program, then the check could be done directly in a pipeline, reading from that program, depending on what it is you'd like to achieve.
    – Kusalananda
    Dec 7 at 23:18

















  • Where does the string come from and why do you have it in a variable? If it's the output of a program, then the check could be done directly in a pipeline, reading from that program, depending on what it is you'd like to achieve.
    – Kusalananda
    Dec 7 at 23:18
















Where does the string come from and why do you have it in a variable? If it's the output of a program, then the check could be done directly in a pipeline, reading from that program, depending on what it is you'd like to achieve.
– Kusalananda
Dec 7 at 23:18





Where does the string come from and why do you have it in a variable? If it's the output of a program, then the check could be done directly in a pipeline, reading from that program, depending on what it is you'd like to achieve.
– Kusalananda
Dec 7 at 23:18











1 Answer
1






active

oldest

votes

















up vote
0
down vote













How about



read size1 unit1 size2 unit2 <<< $(command | sed -n '/Size/ s/^[^ ]* //; s/ Time:.*$//; s#/# #; p')


?






share|improve this answer
















  • 1




    Just FYI, @RudiC (and feel free to flag this as "no longer necessary"), some of your answers are showing up in the "low quality" review queue, likely because the post is largely code. If you provide a bit of commentary to explain what the code is doing, you'll be at less risk of someone voting to delete the answer. On a side note, my (opinion/suggestion) would be to rephrase the text to be more of a statement than a question. It could confuse someone who's reviewing too quickly and thinks you're asking a question of the OP instead of answering. Thanks!
    – Jeff Schaller
    Dec 8 at 13:44










  • Thanks @Jeff Schaller for these hints. I acknowledge there may be (unwritten) rules in these fora, but there's a (my?) personal approach / style as well. Not feeling too comfortable discussing via comments, and not knowing the ropes in here - is there a forum / room for such discussion?
    – RudiC
    Dec 8 at 16:51











  • There is a U&L chat room, at chat.stackexchange.com/rooms/26/dev-chat . It's occasionally busy, but often quiet. I think there may also be a way to create a separate room, although I'm not as familiar with that. Feel free to ping me in chat (join the room, then send something @JeffSchaller) if you'd like to discuss anything further!
    – Jeff Schaller
    Dec 8 at 18:10










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: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
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%2f486690%2fwhile-loop-comparing-two-numbers-from-a-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













How about



read size1 unit1 size2 unit2 <<< $(command | sed -n '/Size/ s/^[^ ]* //; s/ Time:.*$//; s#/# #; p')


?






share|improve this answer
















  • 1




    Just FYI, @RudiC (and feel free to flag this as "no longer necessary"), some of your answers are showing up in the "low quality" review queue, likely because the post is largely code. If you provide a bit of commentary to explain what the code is doing, you'll be at less risk of someone voting to delete the answer. On a side note, my (opinion/suggestion) would be to rephrase the text to be more of a statement than a question. It could confuse someone who's reviewing too quickly and thinks you're asking a question of the OP instead of answering. Thanks!
    – Jeff Schaller
    Dec 8 at 13:44










  • Thanks @Jeff Schaller for these hints. I acknowledge there may be (unwritten) rules in these fora, but there's a (my?) personal approach / style as well. Not feeling too comfortable discussing via comments, and not knowing the ropes in here - is there a forum / room for such discussion?
    – RudiC
    Dec 8 at 16:51











  • There is a U&L chat room, at chat.stackexchange.com/rooms/26/dev-chat . It's occasionally busy, but often quiet. I think there may also be a way to create a separate room, although I'm not as familiar with that. Feel free to ping me in chat (join the room, then send something @JeffSchaller) if you'd like to discuss anything further!
    – Jeff Schaller
    Dec 8 at 18:10














up vote
0
down vote













How about



read size1 unit1 size2 unit2 <<< $(command | sed -n '/Size/ s/^[^ ]* //; s/ Time:.*$//; s#/# #; p')


?






share|improve this answer
















  • 1




    Just FYI, @RudiC (and feel free to flag this as "no longer necessary"), some of your answers are showing up in the "low quality" review queue, likely because the post is largely code. If you provide a bit of commentary to explain what the code is doing, you'll be at less risk of someone voting to delete the answer. On a side note, my (opinion/suggestion) would be to rephrase the text to be more of a statement than a question. It could confuse someone who's reviewing too quickly and thinks you're asking a question of the OP instead of answering. Thanks!
    – Jeff Schaller
    Dec 8 at 13:44










  • Thanks @Jeff Schaller for these hints. I acknowledge there may be (unwritten) rules in these fora, but there's a (my?) personal approach / style as well. Not feeling too comfortable discussing via comments, and not knowing the ropes in here - is there a forum / room for such discussion?
    – RudiC
    Dec 8 at 16:51











  • There is a U&L chat room, at chat.stackexchange.com/rooms/26/dev-chat . It's occasionally busy, but often quiet. I think there may also be a way to create a separate room, although I'm not as familiar with that. Feel free to ping me in chat (join the room, then send something @JeffSchaller) if you'd like to discuss anything further!
    – Jeff Schaller
    Dec 8 at 18:10












up vote
0
down vote










up vote
0
down vote









How about



read size1 unit1 size2 unit2 <<< $(command | sed -n '/Size/ s/^[^ ]* //; s/ Time:.*$//; s#/# #; p')


?






share|improve this answer












How about



read size1 unit1 size2 unit2 <<< $(command | sed -n '/Size/ s/^[^ ]* //; s/ Time:.*$//; s#/# #; p')


?







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 8 at 12:48









RudiC

3,9541312




3,9541312







  • 1




    Just FYI, @RudiC (and feel free to flag this as "no longer necessary"), some of your answers are showing up in the "low quality" review queue, likely because the post is largely code. If you provide a bit of commentary to explain what the code is doing, you'll be at less risk of someone voting to delete the answer. On a side note, my (opinion/suggestion) would be to rephrase the text to be more of a statement than a question. It could confuse someone who's reviewing too quickly and thinks you're asking a question of the OP instead of answering. Thanks!
    – Jeff Schaller
    Dec 8 at 13:44










  • Thanks @Jeff Schaller for these hints. I acknowledge there may be (unwritten) rules in these fora, but there's a (my?) personal approach / style as well. Not feeling too comfortable discussing via comments, and not knowing the ropes in here - is there a forum / room for such discussion?
    – RudiC
    Dec 8 at 16:51











  • There is a U&L chat room, at chat.stackexchange.com/rooms/26/dev-chat . It's occasionally busy, but often quiet. I think there may also be a way to create a separate room, although I'm not as familiar with that. Feel free to ping me in chat (join the room, then send something @JeffSchaller) if you'd like to discuss anything further!
    – Jeff Schaller
    Dec 8 at 18:10












  • 1




    Just FYI, @RudiC (and feel free to flag this as "no longer necessary"), some of your answers are showing up in the "low quality" review queue, likely because the post is largely code. If you provide a bit of commentary to explain what the code is doing, you'll be at less risk of someone voting to delete the answer. On a side note, my (opinion/suggestion) would be to rephrase the text to be more of a statement than a question. It could confuse someone who's reviewing too quickly and thinks you're asking a question of the OP instead of answering. Thanks!
    – Jeff Schaller
    Dec 8 at 13:44










  • Thanks @Jeff Schaller for these hints. I acknowledge there may be (unwritten) rules in these fora, but there's a (my?) personal approach / style as well. Not feeling too comfortable discussing via comments, and not knowing the ropes in here - is there a forum / room for such discussion?
    – RudiC
    Dec 8 at 16:51











  • There is a U&L chat room, at chat.stackexchange.com/rooms/26/dev-chat . It's occasionally busy, but often quiet. I think there may also be a way to create a separate room, although I'm not as familiar with that. Feel free to ping me in chat (join the room, then send something @JeffSchaller) if you'd like to discuss anything further!
    – Jeff Schaller
    Dec 8 at 18:10







1




1




Just FYI, @RudiC (and feel free to flag this as "no longer necessary"), some of your answers are showing up in the "low quality" review queue, likely because the post is largely code. If you provide a bit of commentary to explain what the code is doing, you'll be at less risk of someone voting to delete the answer. On a side note, my (opinion/suggestion) would be to rephrase the text to be more of a statement than a question. It could confuse someone who's reviewing too quickly and thinks you're asking a question of the OP instead of answering. Thanks!
– Jeff Schaller
Dec 8 at 13:44




Just FYI, @RudiC (and feel free to flag this as "no longer necessary"), some of your answers are showing up in the "low quality" review queue, likely because the post is largely code. If you provide a bit of commentary to explain what the code is doing, you'll be at less risk of someone voting to delete the answer. On a side note, my (opinion/suggestion) would be to rephrase the text to be more of a statement than a question. It could confuse someone who's reviewing too quickly and thinks you're asking a question of the OP instead of answering. Thanks!
– Jeff Schaller
Dec 8 at 13:44












Thanks @Jeff Schaller for these hints. I acknowledge there may be (unwritten) rules in these fora, but there's a (my?) personal approach / style as well. Not feeling too comfortable discussing via comments, and not knowing the ropes in here - is there a forum / room for such discussion?
– RudiC
Dec 8 at 16:51





Thanks @Jeff Schaller for these hints. I acknowledge there may be (unwritten) rules in these fora, but there's a (my?) personal approach / style as well. Not feeling too comfortable discussing via comments, and not knowing the ropes in here - is there a forum / room for such discussion?
– RudiC
Dec 8 at 16:51













There is a U&L chat room, at chat.stackexchange.com/rooms/26/dev-chat . It's occasionally busy, but often quiet. I think there may also be a way to create a separate room, although I'm not as familiar with that. Feel free to ping me in chat (join the room, then send something @JeffSchaller) if you'd like to discuss anything further!
– Jeff Schaller
Dec 8 at 18:10




There is a U&L chat room, at chat.stackexchange.com/rooms/26/dev-chat . It's occasionally busy, but often quiet. I think there may also be a way to create a separate room, although I'm not as familiar with that. Feel free to ping me in chat (join the room, then send something @JeffSchaller) if you'd like to discuss anything further!
– Jeff Schaller
Dec 8 at 18:10

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f486690%2fwhile-loop-comparing-two-numbers-from-a-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

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

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?