Programming language and Test commands

Source: Internet
Author: User
Tags arithmetic

Programming Languages:

Problem space: Tasks described using human natural language

Solution space: is to use programming language to describe the implementation steps of the task and display the final result


Programming idea: the ability to translate the syntax format provided by the programming language into a problem-solving idea anytime, anywhere.


For programming language learning:

1. Learn the syntax format of a programming language

2. Use of learning tools (libraries, commands)

3. Algorithms

4. Data structure


The purpose of Learning programming language: To correspond the problem space and space, the most direct way is to use the language habit of the solution space to think


Learn the goals of the programming language:

The most direct way is to use the language habit of the solution space to reflect the problem space;


Shell script Programming:

Shell script content and format:

First line, Absolute beginning, shebang (absolute path of interpreter program)

Note information: The line that occupies the absolute beginning of the #;

In order to be able to highlight the program in the program function, appropriate to add blank lines to separate the different functions of the source code block;

There is a certain indentation

Using bash scripting to implement arithmetic operations:

+

*

/

% modulo operation remainder

**|^ exponentiation

Enhanced arithmetic operation symbols:

+ = Let b=b+1---> Let b+=1

-=

/=

*=

%=

Special Enhanced arithmetic operations:

B=b+1 b+=1 b++


Arithmetic Operation Method:

1.let var= Arithmetic expression

The arithmetic expression is first performed in arithmetic and the result of the operation is saved to the variable var.

2.var=$[Arithmetic expression]

If there is a variable reference in an arithmetic expression, you can use the $ reference or omit the $

Sum=$[c+b] equals SUM [$C + $B]

3.var=$ ((arithmetic expression))

If there is a variable reference in an arithmetic expression, you can use the $ reference or omit the $

4.expr ARGU1 ARGU2 ARGU3

ARGU1 and ARGU3 must be numeric

ARGU2 must be an operation symbol

5.echo "Arithmetic expression" | Bc


Note: * In some cases it is necessary to escape.

Variable:

Weak variables, weakly typed variables, character type (default) numeric (not including floating-point type)


Conditional Test Command:

Test EXPRESSION

Shell built-in commands


[EXPRESSION]

External command


[[EXPRESSION]]

Bash's internal keywords


Note: This type of command generally does not perform the result, only the execution status return value


There are three types of test expressions in the test command:

1. Numerical Test: Binocular operator

-eq: The two values being tested are equal, equal to true, and not as false

-ne: Whether the two values tested are unequal, not equal to true, and are false

-GT: The two values tested to the left are greater than the right, greater than true, less than false

-LT: Whether the left side of the two values tested is less than the right, less than true, greater than false

-ge: Whether the left side of the two values being tested is greater than or equal to the right, greater than or equal to true, less than false

-le: Whether the left side of the two values being tested is less than or equal to the right, less than or equal to true, greater than false


2. String test

Binocular operator:

==|=: The two strings tested are the same, the same is true, and the difference is false.

! =: The two strings tested are not the same, the difference is true, the same is false.

>: The two strings tested correspond to the binary values in the ASCII code table, the left side is greater than the right, is greater than true, and is less than false.

<: The two strings tested correspond to the binary values in the ASCII code table, the left side is less than the right, less than true, and greater than false.

Note: The greater than and less than sign must be used in [[EXPRESSION]]

=~: Tested two strings, the left string can be matched to the right pattern, can match to true, cannot be false.


Monocular operator:

-Z "string": Determines whether the specified string is a null string, NULL is true, and is not NULL or FALSE.

-N "string": Determines whether the specified string is a non-empty string, non-null is true, and Null is false.

Attention:

1. In general, strings should be quoted, single or double quotation marks, according to the actual situation to choose.

2.[[]] and [] in some cases, may have different meanings, distinguish between use.

3. Spaces at both ends of the expression and at both ends of the operator


3. File Status Test

Monocular test:

Test of the existence of the file: If the file being tested exists then it is true and false if it does not exist.

-a|-e

[-e/backup]

File type testing (existence is tested first):

-B File: Whether the file being tested exists and is a block device, exists and is true for block devices, otherwise false.

-C File: whether the files being tested exist and are character devices ...

-D file: Whether the files being tested exist and are directory files ...

-F File: whether the files being tested exist and are normal files ...

-h|-l file: Whether the files being tested exist and are symbolic link files ...

-P File: whether the file being tested exists and is a pipe file ...

-S file: The files being tested are present and are socket files ...

Access rights test for files:

-R file: whether the file being tested exists and whether the current valid user is readable, the file exists and the current valid user is readable as true, otherwise false

-W File: Whether the file being tested exists and whether the current valid user is writable ...

-X file: whether the file being tested exists and whether the current valid user is executable ...

Special permission identification tests for files:

-U file: If the file being tested exists and if the SUID permission is set, the file exists and the SUID permission is set to true, otherwise it is false.

-G File: Whether the file being tested exists and whether the GUID permission is set ...

-K File: whether the files being tested exist and whether sticky permissions are set ...


Ownership test of the file:

-O File: Whether the file being tested exists and whether its owner is the current active user

-G File: Whether the file being tested exists and whether the group is a group of the currently active user


Whether the file contents are empty:

-S file: The file being tested is present and the content is not empty, exists and the content is not empty for true, otherwise false.


Time Stamp test:

-N File: The file being tested has been modified since the last time it was modified.


Binocular test:

File1-ef FILE2: Whether the two files being tested point to the same inode as the same file system with a hard connection

File1-nt FILE2: Two files tested, FILE1 is newer than FILE2

File1-ot FILE2: Two files tested, FILE1 is older than FILE2


You can add a logical operation in a test statement:

The first way of expression:

[-o/tmp/test]&&[-s/tmp/test]

[-o/tmp/test]| | [-s/tmp/test]

! [-o/tmp/test]

The second way of expression:

[-o/tmp/test-a-s/tmp/test]

[-o/tmp/test-o-s/tmp/test]

[ ! -o/tmp/test]

Execution result of the command:

Normal output results

The execution status return value of the command:

0-255

0: Indicates that the command executed successfully

1, 2,127: System reserved;

3-126, 128-255: User-defined execution status return value;

exit[#]

Exit the current Shell login

When the shell script runs, when the Exit command is encountered, the current shell process is terminated immediately, and the script run is stopped, that is, all commands after exit are no longer executed


This article is from the "12657170" blog, please be sure to keep this source http://12667170.blog.51cto.com/12657170/1919257

Programming language and Test commands

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.