Simplest command-line calculator
Clash 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
.
shell calculator
add a comment |Â
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
.
shell calculator
add a comment |Â
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
.
shell calculator
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
shell calculator
edited 11 mins ago
asked 1 hour ago


Fabby
2,67911023
2,67911023
add a comment |Â
add a comment |Â
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 "$@"
add a comment |Â
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>
I'm on bash, but I should really look intozsh
. +1 anyway and Merci! ;-)
– Fabby
14 mins ago
add a comment |Â
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
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
add a comment |Â
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 "$@"
add a comment |Â
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 "$@"
add a comment |Â
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 "$@"
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 "$@"
answered 26 mins ago
Stephen Kitt
154k23340409
154k23340409
add a comment |Â
add a comment |Â
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>
I'm on bash, but I should really look intozsh
. +1 anyway and Merci! ;-)
– Fabby
14 mins ago
add a comment |Â
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>
I'm on bash, but I should really look intozsh
. +1 anyway and Merci! ;-)
– Fabby
14 mins ago
add a comment |Â
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>
In zsh
:
$ autoload zcalc # best in ~/.zshrc
$ zcalc
1> 1+1
2
2> ^D
$ zcalc 5+5
1> 10
2>
answered 20 mins ago


Stéphane Chazelas
292k54543882
292k54543882
I'm on bash, but I should really look intozsh
. +1 anyway and Merci! ;-)
– Fabby
14 mins ago
add a comment |Â
I'm on bash, but I should really look intozsh
. +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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
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%2f480121%2fsimplest-command-line-calculator%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