Basic Shell operators and Shell Operators

Source: Internet
Author: User

Basic Shell operators and Shell Operators
Native bash does not support simple mathematical operations, but can be implemented using other commands, such as awk and expr, which are most commonly used. Expr is an expression computing tool that can be used to evaluate an expression. For example, the two numbers are added together (the quotation marks are used instead of single quotation marks '):

#! /Bin/bashval = 'expr 2 + 2' echo "the sum of the two values: $ val"
Run the script and the output result is as follows:
Sum of two numbers: 4
Note:
  • There must be spaces between expressions and operators. For example, 2 + 2 is incorrect and must be written as 2 + 2.
  • The complete expression must be included in ''. Note that this character is not a common single quotation mark.

The following table lists commonArithmetic OperatorsAssume that variable a is 10 and variable B is 20:

Note:

  • A backslash (\) must be added to the front side of the multiplication sign (*) to realize multiplication.
  • The conditional expression must be placed between square brackets with spaces.
Relational operatorsOnly numbers are supported. strings are not supported unless the value of a string is a number. The following table lists commonly used Relational operators. Assume that variable a is 10 and variable B is 20.

The following table lists commonBoolean operatorAssume that variable a is 10 and variable B is 20.

The following describesLogical operatorsAssume that variable a is 10 and variable B is 20.

The following table lists commonString OperatorsAssume that variable a is "abc" and variable B is "efg"

 

File test operatorUsed to detect various properties of Unix files

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.