Linux Learning Shell script-------references and operators

Source: Internet
Author: User
Tags bitwise operators logical operators

[This is my own study notes, welcome reprint, but please specify the source:http://blog.csdn.net/jesson20121020]

Variables and substitution operations, one of the easiest mistakes to make when performing variable substitution in a script is to refer to the error, so it is necessary to look at the meaning and function of the various quotes represented.

References:
double quote ""

Use double quotation marks to reference any character or string except the character $, ', \ \. As shown below:

[Email protected]:~/develop/workspace/shell_workspace$ echo-e "Hello $SHELL ' \n* jesson ' echo 20121020 '" Hello/bin/bash ' * jesson20121020

single quote "'

Single quotes are similar to double quotes, but the shell ignores any reference values. In other words, if the special meaning is masked (not masked \), all the characters in the quotation marks, including the quotation marks, are used as a string.

As the above example shows, we will replace the outer double quotes with single quotes this time.

[Email protected]:~/develop/workspace/shell_workspace$ echo-e ' Hello $SHELL \n* jesson ' echo 20121020 ' Hello $SHELL * jes Son ' Echo 20121020 '
It can be seen that except for \ n, the other special symbols are all blocked.

anti-quote "'

Anti-quotes are used to set the output of system commands to variables. The shell takes the contents of the anti-quotation mark as a system command and executes its contents.

[Email protected]:~/develop/workspace/shell_workspace$ echo "Hello ' echo 20121020 '" Hello 20121020

back slash \

Backslashes can block special meanings. The following characters contain special meanings:& * + ^ $ ' "|?.

[Email protected]:~/develop/workspace/shell_workspace$ echo *helloworld.sh parm.sh searchfile.sh[email protected]:~/ develop/workspace/shell_workspace$ Echo \**
  

Operator:

Operator is an instruction issued to a computer

Arithmetic objects:

-Numbers, characters

-Variable

-Expressions: Combinations of operators and operands

operator Type:

   &[] tells the shell to evaluate an expression in parentheses.

Bitwise operators:

~ (inverse operator),<< (shift left),>> (right),& (with), | (or), ^ (XOR)

[Email protected]:~/develop/workspace/shell_workspace$ echo $[-]-3[email Protected]:~/develop/workspace/shell_ workspace$ echo $[2<<1]4[email protected]:~/develop/workspace/shell_workspace$ echo $[2>>1]1[email protected]:~/develop/workspace/shell_workspace$ echo $[2&3]2[email Protected]:~/develop/workspace/shell_ workspace$ echo $[2|3]3[email protected]:~/develop/workspace/shell_workspace$ echo $[2^3]1

logical operators:

&& (Logic and), | | (logical OR), >,==,<,!=

[Email protected]:~/develop/workspace/shell_workspace$ echo $[1&1]1[email Protected]:~/develop/workspace/shell _workspace$ echo $[1&0]0[email protected]:~/develop/workspace/shell_workspace$ echo $[1|0]1[email protected]:~/ develop/workspace/shell_workspace$ echo $[1|1]1[email protected]:~/develop/workspace/shell_workspace$ echo $[0|0]0

Assignment operators:

=, + =,-=, *=,/=,%=, &=, ^=, |=, <<=, >>=

Let $count = $count + $change

Let $count + = $change

[Email protected]:~/develop/workspace/shell_workspace$ var=10[email Protected]:~/develop/workspace/shell_ workspace$ let Var+=4[email protected]:~/develop/workspace/shell_workspace$ Echo $var 14

expression Substitution

$[] and $ (()) are used for expression evaluation.

$[] can accept numbers of different cardinality:

-[Base#n] n represents any cardinality from 2 to 36.

[Email protected]:~/develop/workspace/shell_workspace$ echo $ ((8+6)) 14[email Protected]:~/develop/workspace/shell_ workspace$ Echo $[10#8+1]9


Linux Learning Shell script-------references and operators

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.