Execution of shell scripts and files

Source: Internet
Author: User

1. Shell Script Program

The shell is the "shell" of the operating system, and the shell provides users with a human-computer interface. All the user's actions on the computer and the data that the computer obtains are managed by the shell.

Shell generally divided into 2 categories: (1), graphic shell (2) text Shell;shell on the operating system is just a common application, no matter how complex the form, can be replaced with the need at any time.

We are programmed to study the word Shell: command-line,

When a user logs on to a Linux system, a shell process is turned on to provide the user with a human-computer interaction service, and the user can provide the command to the shell process, which executes commands and feedback information;

View Bash process: Ps-ef | grep bash

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/86/DB/wKiom1fNPyriZ_pLAABrHe7Cisc237.png-wh_500x0-wm_3 -wmp_4-s_701037526.png "title=" Qq20160905174706.png "alt=" Wkiom1fnpyriz_plaabrhe7cisc237.png-wh_50 "/>


2. Shell Model Analysis

(1) User, kernel, computer hardware

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/86/DB/wKiom1fNQROwekLlAAAfviriGSc365.png-wh_500x0-wm_3 -wmp_4-s_3441044611.png "title=" Qq20160905175518.png "alt=" Wkiom1fnqrowekllaaafvirigsc365.png-wh_50 "/>

(2), kernel and shell

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/86/DA/wKioL1fNQc2D9nXDAAASmoVdBBM068.png-wh_500x0-wm_3 -wmp_4-s_817139881.png "title=" Qq20160905175828.png "alt=" Wkiol1fnqc2d9nxdaaasmovdbbm068.png-wh_50 "/>

3. Shell Script

: The various shell commands are edited into a file, and the file is given to the shell program for parsing execution, and the script is parsing the execution of the sequential logic program, the interpreter in the process is the specified interpreter, the default is the shell process.

(1), compile execution: The source program is compiled into some executable independent of another file, the subsequent execution of the program, the use of compiled results files, and the source program has no relationship.

(2), interpretation of the execution: the source program to some kind of interpreter, the interpreter to the source program compiled at the same time, the execution of the results of the compilation. The result file is not generated at compile time.

4, the principle of file execution process

All files on Linux can be executed, so all files are defined to be executed.

The only binary code that a computer can execute directly is the binary code that the computer can recognize.

However, most files only contain non-executable binary machine languages.

The model is as follows:

Sequence diagram of Linux files being executed:

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/86/DB/wKioL1fNSmfD1Q6JAABwfvXsAOk138.png-wh_500x0-wm_3 -wmp_4-s_1969236524.png "title=" Qq20160905183506.png "alt=" Wkiol1fnsmfd1q6jaabwfvxsaok138.png-wh_50 "/>

The execution of all files is handled like this!!! (Linux file Execution sequence diagram).

5. Write a simple shell script

(1), the simplest shell program

#!/bin/bashecho Hello Shell

#: Specifies the interpreter for the current script

#之后的内容就有既定的解释器解释执行.

(2), where does the shell script start?

All sequential logic programming languages have portals, but they don't always have entry functions;

The entrance to the shell script is the first command line that can be executed 6;

From a point of view, the shell script is the equivalent of a whole bunch of command lines listed together.

6. Shell Variables

(1), variable is the space of data storage, usually corresponds to a piece of memory area;

All variables in the shell are treated as strings, or the shell has only one data type: string;

(2), the definition of variables

Variable name = value

The definition of a variable: the variable is defined immediately when it is first assigned or directly used, and the default value is an empty string if it is used for the first time as a non-assignment.

(3), using variables

$: Take the value of the variable, take the rule: Remove the value of the variable to replace the entire $ expression;

$ expression Format: $ variable name ${variable name} ....

7. Shell process and shell variables

Each shell process maintains a table of its own shell variables. When the shell process dies, the shell variable tables it maintains are recycled.

The variables in the shell do not have the partition of data type, but they have functional division;

(1), User variables

only the variables owned by the current shell process, whose child processes or other processes cannot access these variables, and cannot inherit or copy them. This makes the variable available only to the currently logged-in user-so called the user variable.

(2), environment variables

Can be copied by the child process of the current shell process;

User variables can be upgraded to environment variables, export by command;

Environment variables can be deleted by command unset;

(3), Position variable

Used to pass parameters from the command-behavior script program;

$0~ $N (N >= 0) $ A: Represents the command name, $1~ $N: Represents the first to nth command-line arguments;

(4), default command-line variable

$#: Number of command line arguments

$*: Command line all parameters



This article is from the "11586096" blog, please be sure to keep this source http://11596096.blog.51cto.com/11586096/1846615

Execution of shell scripts and files

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.