Simplest command-line calculator

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











up vote
2
down vote

favorite












Issue:



Every now and then I need to do simple arithmetic in a command-line environment. E.G. given the following output:



Disk /dev/sdb: 256GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 106MB 105MB fat32 hidden, diag
2 106MB 64.1GB 64.0GB ext4
3 64.1GB 192GB 128GB ext4
5 236GB 256GB 20.0GB linux-swap(v1)


What's the easiest way to calculate on the command line the size of the unallocated space between the 192GB partition end and the 236GB start of the next partition?



What I've tried already:



bc



bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
236-128
108
quit


where the bold above is all the stuff I need to type to do a simple 236-128.



expr



expr 236 - 128


where I need to type spaces before and after the operator as expr 1+1 just echoes 1+1.










share|improve this question



























    up vote
    2
    down vote

    favorite












    Issue:



    Every now and then I need to do simple arithmetic in a command-line environment. E.G. given the following output:



    Disk /dev/sdb: 256GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags:

    Number Start End Size File system Name Flags
    1 1049kB 106MB 105MB fat32 hidden, diag
    2 106MB 64.1GB 64.0GB ext4
    3 64.1GB 192GB 128GB ext4
    5 236GB 256GB 20.0GB linux-swap(v1)


    What's the easiest way to calculate on the command line the size of the unallocated space between the 192GB partition end and the 236GB start of the next partition?



    What I've tried already:



    bc



    bc
    bc 1.06.95
    Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
    This is free software with ABSOLUTELY NO WARRANTY.
    For details type `warranty'.
    236-128
    108
    quit


    where the bold above is all the stuff I need to type to do a simple 236-128.



    expr



    expr 236 - 128


    where I need to type spaces before and after the operator as expr 1+1 just echoes 1+1.










    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Issue:



      Every now and then I need to do simple arithmetic in a command-line environment. E.G. given the following output:



      Disk /dev/sdb: 256GB
      Sector size (logical/physical): 512B/512B
      Partition Table: gpt
      Disk Flags:

      Number Start End Size File system Name Flags
      1 1049kB 106MB 105MB fat32 hidden, diag
      2 106MB 64.1GB 64.0GB ext4
      3 64.1GB 192GB 128GB ext4
      5 236GB 256GB 20.0GB linux-swap(v1)


      What's the easiest way to calculate on the command line the size of the unallocated space between the 192GB partition end and the 236GB start of the next partition?



      What I've tried already:



      bc



      bc
      bc 1.06.95
      Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
      This is free software with ABSOLUTELY NO WARRANTY.
      For details type `warranty'.
      236-128
      108
      quit


      where the bold above is all the stuff I need to type to do a simple 236-128.



      expr



      expr 236 - 128


      where I need to type spaces before and after the operator as expr 1+1 just echoes 1+1.










      share|improve this question















      Issue:



      Every now and then I need to do simple arithmetic in a command-line environment. E.G. given the following output:



      Disk /dev/sdb: 256GB
      Sector size (logical/physical): 512B/512B
      Partition Table: gpt
      Disk Flags:

      Number Start End Size File system Name Flags
      1 1049kB 106MB 105MB fat32 hidden, diag
      2 106MB 64.1GB 64.0GB ext4
      3 64.1GB 192GB 128GB ext4
      5 236GB 256GB 20.0GB linux-swap(v1)


      What's the easiest way to calculate on the command line the size of the unallocated space between the 192GB partition end and the 236GB start of the next partition?



      What I've tried already:



      bc



      bc
      bc 1.06.95
      Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
      This is free software with ABSOLUTELY NO WARRANTY.
      For details type `warranty'.
      236-128
      108
      quit


      where the bold above is all the stuff I need to type to do a simple 236-128.



      expr



      expr 236 - 128


      where I need to type spaces before and after the operator as expr 1+1 just echoes 1+1.







      shell calculator






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 11 mins ago

























      asked 1 hour ago









      Fabby

      2,67911023




      2,67911023




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          You can greatly reduce the amount of typing needed to use bc:



          $ bc <<<"236-128"
          108
          $ bc <<<"1+1"
          2


          (assuming your shell supports that).



          If you’d rather have that as a function:



          c() 
          echo "$@"





          share|improve this answer



























            up vote
            2
            down vote













            In zsh:



            $ autoload zcalc # best in ~/.zshrc
            $ zcalc
            1> 1+1
            2
            2> ^D
            $ zcalc 5+5
            1> 10
            2>





            share|improve this answer




















            • I'm on bash, but I should really look into zsh. +1 anyway and Merci! ;-)
              – Fabby
              14 mins ago

















            up vote
            1
            down vote













            Reading this pages comments, I see a unix/linux program called calc, that does exactly what you want. If on debian / ubuntu / derivatives:



            sudo apt-get install apcalc


            then



            calc 236-128





            share|improve this answer






















            • Not perfect, but good enough for an upvote. Misunderstanding corrected in chat and downvote removed by other user. Deleted my own (inferior) answer... ;-)
              – Fabby
              15 mins ago











            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%2f480121%2fsimplest-command-line-calculator%23new-answer', 'question_page');

            );

            Post as a guest






























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted










            You can greatly reduce the amount of typing needed to use bc:



            $ bc <<<"236-128"
            108
            $ bc <<<"1+1"
            2


            (assuming your shell supports that).



            If you’d rather have that as a function:



            c() 
            echo "$@"





            share|improve this answer
























              up vote
              4
              down vote



              accepted










              You can greatly reduce the amount of typing needed to use bc:



              $ bc <<<"236-128"
              108
              $ bc <<<"1+1"
              2


              (assuming your shell supports that).



              If you’d rather have that as a function:



              c() 
              echo "$@"





              share|improve this answer






















                up vote
                4
                down vote



                accepted







                up vote
                4
                down vote



                accepted






                You can greatly reduce the amount of typing needed to use bc:



                $ bc <<<"236-128"
                108
                $ bc <<<"1+1"
                2


                (assuming your shell supports that).



                If you’d rather have that as a function:



                c() 
                echo "$@"





                share|improve this answer












                You can greatly reduce the amount of typing needed to use bc:



                $ bc <<<"236-128"
                108
                $ bc <<<"1+1"
                2


                (assuming your shell supports that).



                If you’d rather have that as a function:



                c() 
                echo "$@"






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 26 mins ago









                Stephen Kitt

                154k23340409




                154k23340409






















                    up vote
                    2
                    down vote













                    In zsh:



                    $ autoload zcalc # best in ~/.zshrc
                    $ zcalc
                    1> 1+1
                    2
                    2> ^D
                    $ zcalc 5+5
                    1> 10
                    2>





                    share|improve this answer




















                    • I'm on bash, but I should really look into zsh. +1 anyway and Merci! ;-)
                      – Fabby
                      14 mins ago














                    up vote
                    2
                    down vote













                    In zsh:



                    $ autoload zcalc # best in ~/.zshrc
                    $ zcalc
                    1> 1+1
                    2
                    2> ^D
                    $ zcalc 5+5
                    1> 10
                    2>





                    share|improve this answer




















                    • I'm on bash, but I should really look into zsh. +1 anyway and Merci! ;-)
                      – Fabby
                      14 mins ago












                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    In zsh:



                    $ autoload zcalc # best in ~/.zshrc
                    $ zcalc
                    1> 1+1
                    2
                    2> ^D
                    $ zcalc 5+5
                    1> 10
                    2>





                    share|improve this answer












                    In zsh:



                    $ autoload zcalc # best in ~/.zshrc
                    $ zcalc
                    1> 1+1
                    2
                    2> ^D
                    $ zcalc 5+5
                    1> 10
                    2>






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 20 mins ago









                    Stéphane Chazelas

                    292k54543882




                    292k54543882











                    • I'm on bash, but I should really look into zsh. +1 anyway and Merci! ;-)
                      – Fabby
                      14 mins ago
















                    • I'm on bash, but I should really look into zsh. +1 anyway and Merci! ;-)
                      – Fabby
                      14 mins ago















                    I'm on bash, but I should really look into zsh. +1 anyway and Merci! ;-)
                    – Fabby
                    14 mins ago




                    I'm on bash, but I should really look into zsh. +1 anyway and Merci! ;-)
                    – Fabby
                    14 mins ago










                    up vote
                    1
                    down vote













                    Reading this pages comments, I see a unix/linux program called calc, that does exactly what you want. If on debian / ubuntu / derivatives:



                    sudo apt-get install apcalc


                    then



                    calc 236-128





                    share|improve this answer






















                    • Not perfect, but good enough for an upvote. Misunderstanding corrected in chat and downvote removed by other user. Deleted my own (inferior) answer... ;-)
                      – Fabby
                      15 mins ago















                    up vote
                    1
                    down vote













                    Reading this pages comments, I see a unix/linux program called calc, that does exactly what you want. If on debian / ubuntu / derivatives:



                    sudo apt-get install apcalc


                    then



                    calc 236-128





                    share|improve this answer






















                    • Not perfect, but good enough for an upvote. Misunderstanding corrected in chat and downvote removed by other user. Deleted my own (inferior) answer... ;-)
                      – Fabby
                      15 mins ago













                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    Reading this pages comments, I see a unix/linux program called calc, that does exactly what you want. If on debian / ubuntu / derivatives:



                    sudo apt-get install apcalc


                    then



                    calc 236-128





                    share|improve this answer














                    Reading this pages comments, I see a unix/linux program called calc, that does exactly what you want. If on debian / ubuntu / derivatives:



                    sudo apt-get install apcalc


                    then



                    calc 236-128






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 23 mins ago









                    Vlastimil

                    7,1831153129




                    7,1831153129










                    answered 41 mins ago









                    number9

                    1854




                    1854











                    • Not perfect, but good enough for an upvote. Misunderstanding corrected in chat and downvote removed by other user. Deleted my own (inferior) answer... ;-)
                      – Fabby
                      15 mins ago

















                    • Not perfect, but good enough for an upvote. Misunderstanding corrected in chat and downvote removed by other user. Deleted my own (inferior) answer... ;-)
                      – Fabby
                      15 mins ago
















                    Not perfect, but good enough for an upvote. Misunderstanding corrected in chat and downvote removed by other user. Deleted my own (inferior) answer... ;-)
                    – Fabby
                    15 mins ago





                    Not perfect, but good enough for an upvote. Misunderstanding corrected in chat and downvote removed by other user. Deleted my own (inferior) answer... ;-)
                    – Fabby
                    15 mins ago


















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480121%2fsimplest-command-line-calculator%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery