Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commands for using calculators on the Linux command line

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about using calculators on the Linux command line. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. How to use bc to perform calculations in Linux

Bc is a language that supports arbitrary precision numbers in the way of interactive statement execution, and its syntax is similar to that of C language.

There is a standard math library available in bc's command line options. If required, bc will define the standard math library before processing any files, and bc will process the code of each file listed in the command in the order in the command.

By default, bc is installed in all Linux distributions. If you do not have bc on your system, you can install it yourself by following the command below:

For Fedora systems, use the DNF command to install

$sudo dnf install bc

For Debian/Ubantu systems, use the APT-GET or APT command to install

$sudo apt install bc

For Arch Linux-based systems, use the Pacman command to install

$sudo pacman-S bc

For RHEL/CentOS systems, use the YUM command to install

$sudo yum install bc

For openSUSE Leap systems, use the Zypper command to install

$sudo yum install bc

How to use the bc command

We can use the bc command to perform various calculations such as +-* / ^% directly in the terminal.

$bc bc 1.07.1 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 1 "2 3 10-5 5 2 0 5 10 10 10 quit 2 5 13 1 2 2 2 (2-4) * 5-5 25 2 ^ 3 8 8% 3 2 quit

Use-l to define the standard math library. By default, 3Compact 5 is 0 in the result of bc, because it's just rounding. If you want to get the right answer, you need to use the-l option.

$bc-l bc 1.07.1 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 3/5. 60000000000000000000 quit

two。 How to use calc for calculation in Linux

Calc is an arbitrary precision calculator, a simple calculator that can perform various calculations on the command line.

If you need to install the calc command, you can refer to the bc command installation method above.

How to use the calc command

We can use calc to perform various types of calculations interactively in the terminal.

$calc C-style arbitrary precision calculator (version 2.12.7.1) Calc is open software. For license details type: help copyright [Type "exit" to exit, or "help" for help.]; 5 + 1 6; 5-14; 5 + 2 10; 10 + 2 5; 13% 5 3; 2 ^ 4 16; 9 ^ 0.53; quit

Of course, you can also use it in non-interactive mode:

$calc 3AGO 5 0.6

3. How to use expr for calculation in Linux

Expr is part of the core toollibrary, so we don't need to install it.

We can use the following command to do the basic calculation:

$expr 2 + 3 6$ expr 6-24$ expr 3 * 4 12$ expr 15 / 3 5

However, it is important to note that numbers and symbols need to be separated by spaces, otherwise the command will not recognize the expression you write:

$expr 2 "3 2" 3$ expr 2 "3 2" 3

4. How to use gcalccmd for calculation in Linux

Gnome-calculator is the official calculator for the GNOME desktop environment. Gcalccmd is the console version of the Gnome Calculator tool. By default, gcalccmd is installed on the GNOME desktop.

Use the gcalccmd command for calculation

Gcalccmd also has an interactive interface, and the formula can be written just like other calculators.

$gcalccmd > 5x 16 > 5-14 > 5x 210 > 10max 25 > sqrt (16) 4 > 3max 50.6 > quit

5. How to use qalc for calculation in Linux

Qalculate is a multi-functional cross-platform desktop calculator. It is easy to use, but it is very powerful. It provides some powerful multi-functional math libraries, as well as some practical tools to meet daily needs (such as currency conversion and percentage calculation, etc.).

Qalculate features include a large number of customizable function libraries, unit calculations and conversions, symbolic calculations (including integrals and equations), arbitrary precision, uncertainty propagation, interval arithmetic, graphics and user-friendly interfaces (GTK + and CLI).

For Fedora systems, use the DNF command to install

$sudo dnf install libqalculate

For Debian/Ubantu systems, use the APT-GET or APT command to install

$sudo apt install libqalculate

For Arch Linux-based systems, use the Pacman command to install

Sudo pacman-S libqalculate

For RHEL/CentOS systems, use the YUM command to install

$sudo yum install libqalculate

For openSUSE Leap systems, use the Zypper command to install

$sudo zypper install libqalculate

Use the qalc command for calculation

$qalc > 5 USD to INR It has been 15 day 1 = 6 > ans*2 ans*2 = 12 > ans-2 ans-2 = 10 > 1 USD to INR It has been 36 day (s) since the exchange rates last were updated. Do you wish to update the exchange rates now? Y error: Failed to download exchange rates from coinbase.com: Resolving timed out after 15000 milliseconds. 1 * dollar = approx. INR 69.638581 > 10 USD to INR 10 * dollar = approx. INR 696.38581 > quit

6. How to use the Shell command to calculate

In fact, under the Shell command line, we can directly use echo, awk and other commands for direct calculation, which is very convenient.

$echo $((5x5)) 10$ cat data | awk'{sum+=$1} END {print "Sum =", sum}'# calculate the sum of the data in the data file. Thank you for reading! This is the end of this article on "what are the commands for using calculators on the Linux command line?". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report