Linux notes--extended regular expressions, bash scripts-variables, conditional judgments, arithmetic operations

Source: Internet
Author: User
Tags arithmetic

  • Regular Expressions: There are two classes, one: Basic RegExp two: extended (extended regular expression) their partial metacharacters are different, the meanings are different.

  • grep: Commands that filter text using basic regular expressions or defined patterns,-e; Using extended regular expressions-a numbers: not only the rows that match, but also the next few rows-B numbers: Not only the rows that match, but also the first few lines,-C numbers: Not only the rows that match, but also the lines that appear before and after

  • To extend the regular expression:

  • which. [] [^] * ^ $ \< \> is the same as grep? Same as \?: Meaning, can not write \ +: its first character appears at least once {m,n} (): Do not use \ Parentheses to denote a whole |: or meaning (note: grep-e = egrep Extended expression, Fgrep: regular expression not supported)

  • Shell Programming: Script Programming

  • Programming Languages: Machine language (0 1 code) assembly language high-level languages

  • Static language: C C + + Java C # compiled language, must be fully converted before execution to execute, strongly typed language (variables must be declared before use, and even initialization)

  • Dynamic language: Php python Shell perl solution-type language, side-conversion side execution, weak type language (variable time does not need to distinguish between types, the default is a string)

  • Process oriented: problem solving process itself (Shell C)

  • Object-oriented: Abstract a project to be implemented into an object and define actions between objects (Java Python perl C + +)

  • Memory: Addressable storage unit

  • Variables: Memory space, (variable assignment: variable name = value)

  • Variable Naming requirements:

  • 1. Can only contain letters, numbers and underscores and cannot begin with a number

  • 2. You should not duplicate the existing environment variables in the system

  • 3. It is best to see the effect of the famous meaning

  • Variable type: Format for storing data, integer, Float, Boolean (true or FALSE) to determine the storage format and length of the data beforehand

  • Logical operations: With or non-XOR or

  • With: 1 0 = 0 0 1 = 0 1 1 = 1 0 0 = 0 (equivalent to in-circuit with gate Circuit)

  • Or: 1 0 = 1 0 1 = 1 1 1 = 1 0 0 = 0 (equivalent to the non-gate circuit in the circuit)

  • Non -:! (0) = 1! (1) = 0 (single-mesh operator)

  • XOR: 1 0 = 1 0 1 = 1 1 1 = 0 0 0 = 0 (same as false, different is true)

  • Short-circuit logic: short-circuit and: When the first condition is false, the second conditional expression is skipped and not executed. Short circuit or: when the first condition is true, skips the second conditional expression and does not execute.

  • Bash Variable type: environment variable (local variable, inverse wrong) position variable special variable (system variable)

  • Reference variable: ${varname} brackets can omit echo ".... ${varname} ..." (double quotes when referencing variables, single quotes when not referenced)

  • Local: Varname=value scope: Entire bash process reference

  • Partial: Local varname=value scope: only useful for the current code snippet

  • Environment variables: scope: Current shell process and its sub-processes, export varname=value can also varname=value export VALUE

  • When the script executes, it starts a child shell process, and the script that starts on the command line inherits the current shell environment variable, and the system automatically executes the script (not the command line startup) that needs to self-define the required environment variables

  • Location variables: $ $ $ ....

  • Special variables: $?  Previous command execution status return value (Echo $?) (Note: Program execution may have two types of return value execution status return code 0-255 0: To perform the correct return value 1 2 127: Reserved for the system, the other is the return value of the execution error)

  • /dev/null: Software device (analog) bit backet

  • Undo variable: unset VARNAME ($VARNAME the value in the Undo variable) (the variable in the script will be revoked after the script ends)

  • View variables in the current shell: set (all variables)

  • To view environment variables in the current shell: Printenv,env,export

  • Add a variable to an existing variable: animals=varname (animals= $ANIMALS: VARNAME) (Export path= ....: $PATH) can also be added to the front (path= $PATH: ...)

  • Script: Command stack, according to the actual need to combine the command flow control mechanism to implement the source program

  • Shebang: Magic number #! /bin/bash

  • Script execution:

  • 1. Add path to execution

  • 2. Direct Join path execution

  • 3. Interpreter Plus file name

  • How to achieve conditional judgment in bash:

  • Judging type: 1. Integer judgment 2. String Judgment 3. File judgment (whether the file exists)

  • To determine an expression:

  • 1.[expression]

  • 2.[[expression]]

  • 3.test expression

  • The logical relationship between bash commands:

  • Logic and:&&

  • Logical OR: | |

  • (both meet the short circuit logic)

  • Integer comparison (multi-mesh):

  • -eq: Determines whether two integers are equal ($A-eq $B)-ne: Two integers are judged to be unequal-GT: Judging one number is greater than the other-lt: Judging if one number is less than the other-QE: greater than or equal to-le: less than or equal to

  • Conditional judgment, control structure

  • Single-branch if statement:

  • if judgment condition; Then

  • Statement1

  • Statement2 ....

  • Fi

  • Two-branch if statement:

  • if judgment condition; Then

  • Statement1

  • Statement2 ....

  • Else

  • Statement1

  • Fi

  • Arithmetic operations in the shell:

  • 1.let $c = $A + $B

  • 2.$[]:c=$[$A + $B]

  • 3.$ (()): c=$ (($A + $B))

  • Each operand and operator in a 4.expr operation expression has a space and is referenced by a command: c= ' expr $A + $B '


This article is from the "stupid Bird first-FAI" blog, please be sure to keep this source http://benniaoxianhui.blog.51cto.com/10463960/1679198

Linux notes--extended regular expressions, bash scripts-variables, conditional judgments, arithmetic operations

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.