Programming language and Shell programming basics

Source: Internet
Author: User
Tags call shell shebang

Bash features multi-command execution:

$()

Pipelines: Inter-process Communication (IPC)

Sequential execution Structure:

Semicolon

Select execution structure: (Logical operation)

With: Logical multiplication,&&

0:success-->true

1-255:failure-->false

True&&true = True

True&&false = False "and" short-circuit logic operation:

As long as the first operand is false, the result of its logical operation must be false, and if Command1 can execute successfully, then Command2 will be executed and Command2 will not be executed if Command1 cannot execute successfully.


Or: logical addition, | | Two lines

Only two of the results are false

ture | | false = Ture

The result must be true as long as the first operand is true

If Command1 is executed successfully, COMMAND2 will not need to execute

With and or both binocular operators



Non: logical inversion,! : Monocular operator

! String: Reading the contents of the history command space

! Command

! true = False

! Command1 $$ command2 equivalent to Command1 | | Command2


Logical operation Symbol Priority:! > $$ > | |

Demogan Law:


XOR: Comparison of two operands is different, if different, the group logical operation result is true, if the same, then the result of the logical operation is False


Shell script Programming:

What is programming: Writing Program source code

In order to enable users to use the computer, you can let the computer to do some tasks in a fee-interactive way, you need to make these tasks into a file, so that the computer sequential acquisition, so as to complete the task

Programming Languages:

Advanced Language:

Depending on how the source code is handled:

Compile run language:

Source code-compiler (compile)--assembler (assembly)--"Linker (link to library)"--binary files that can be executed directly

Explain the running language:

Source code--Directly start the interpreter program corresponding to the source code, executed by the interpreter side of the compiler side

Depending on the implementation of the functionality in its assembly process, it is called crying or calling external program files into:

Full programming language: Programming with libraries or programming components

Script programming Language: Interpreter:

Shell script: Call Shell program, second call required external command file: command interpreter

Provides a single-function programming interface: Support for process-editing logic

According to the programming paradigm: Program = instruction + data

Programming Languages:

The data and data structure are designed around the instruction (algorithm), the information is the instruction service

Object-Type programming language:

Data-centric, instantiating data into classes, and deploying directives around the needs of data

Shell script Programming

An over-programming language that interprets running, since running with external program files

What is a shell script?

Plain Text Documents

A combination of a large number of commands that address user issues based on user needs

Performs idempotent (the result of any command execution is the same)

Many commands do not have "idempotent", and in shell scripts it is necessary to use a lot of program logic to determine whether a command meets its operating conditions to avoid serious errors during operation

The code content in the shell script:

1, the first line must be shebang, the interpreter path, must occupy the absolute beginning; at execution time, start the appropriate interpreter to interpret the many commands in the script:

#!/bin/bash

2, in the shell, in addition to the Shebang, to # occupy the absolute first line of content, are comment lines; The interpreter ignores the contents of such navigation.

3. Explanation ignores all blank lines in the script

4, a lot of commands and keywords (if,else,then,do,while,for ... )

Note: Once the shell script is running, it is in the current shell according to the shebang instructions, open an interpreter (child shell)

Explains the contents of the line code, the content of the shell script is implemented in a child shell process

We can use editors to write shell scripts

Nano,vi,vim,emacs,pico, it is recommended to use VIM

Convention, the suffix of the script file name is. sh, or it can be added without

How the script works:

1. Assign execute permissions to the script file and run the file directly

chmod +x/path/to/script_file

If the script file name does not write to the file path when you execute it, you must make sure that the file is found in the path that is saved in your PATH variable

2, direct search by using the interpreter to run the script, the script as the parameters of the interpreter command


Low-level language:

Assembly





Programming language and Shell programming basics

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.