Shell operators: Shell arithmetic operators, relational operators, Boolean operators, string operators, and so on

Source: Internet
Author: User
Tags arithmetic arithmetic operators

Bash supports many operators, including arithmetic operators, relational operators, Boolean operators, string operators, and file test operators.

Native bash does not support simple math operations, but can be implemented with other commands, such as awk and expr,expr, which are most commonly used.
Native bash support does not support mathematical calculations I'm not sure, but it does the same thing:

#!/bin/bashval22))echo'total value:' $valval 2 2 ]echo'total value:'$val

I think the current version of Bash native is supported by compute


Expr is an expression evaluation tool that uses it to perform evaluation operations on expressions.

For example, two numbers are added:

#!/bin/bashval=$ (expr22)echo'total value:  '$val

Run the script output:

Total Value:4

Two points Note:

    • There are spaces between the expression and the operator, such as the 2 + 2, which is different from most of the programming languages we are familiar with.
    • The complete expression is to be contained, note that this character is not a common single quote, below the ESC key.
Arithmetic operators

Let's take a look at an example that uses arithmetic operators:

Shell operators: Shell arithmetic operators, relational operators, Boolean operators, string operators, and so on

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.