Principle of shell programming

Programming principle:
1, Introduction to Programming
drive hardware default can not be used
CPU control hardware, the need for command communication between different hardware device manufacturers, we need drivers to "translate";
more nearly and development engineers to learn "assembly language"; and "assembly language" is limited by the manufacturers;
the underlying C C ++ assembly language is
now programming:
based on high-level language, as well as ultra-high-level language, better enable programmers to achieve programming
classification of programming languages:
high-level language
super-high-level language to be translated into computer-readable language (binary instructions)
interpreted - translated line by line execution, the Java Python shell
bash -x filename.sh
compiled --- once compiled, all of the implementation of C language C ++ C # java
= data + instruction program
object-oriented programming language --- focus data
for the process to focus on instruction ---
implementation programming language:
[] line by line
1, the order of execution
2 repeatedly executed for (traverse) the while (loop condition) until (while contrast)
3. run the branch if case ---

2, shell scripting language introduced
advantages: Call os (operating system) command line to achieve all functions;
Disadvantages: No library calls (to distinguish Python)

shell scripts include: 1 * command * (very important) 2, variable (global variables, local variables, local variables, parameter passing) 3, the logic

first sentence of the shell! ! ! (Must be written)
# / bin / bash -! Custom script interpreter (# is generally considered a comment line, where special) the shebang
! # / Usr / bin / Python

/ etc / shells - to view the current program supported by the system shell
echo $ SHELL - check the current session of the shell program
/ etc / passwd - developed to support the user's default shell program (/ sbin / nologin)

shell execution:
1, bash command to execute the script
-n see a shell script logic error (Note: the word may be wrong no matter)
-x Progressive script execution (convenience shoot the wrong)
2, authorize chmod u + x filename .sh
use the full path to execute the script, you can

3, variables
Environment Variables
Local variables declare command - Define variable type
local local variables used in the function

Variable types:
numeric:
1, shaping int
2, float a float
. 3, 01 Boolean (true or false) (True False)
string:
1, and ordinary character string
2, the array

Classification of programming languages:
a strongly typed language - the value must be defined in order to carry out the processing operation or
a weakly typed language - programming language may automatically identify the type of variable
[* * polymorphic data having a plurality of attributes, attribute depends on the final use of in which data and operation]

Parameter passing
$ -? Command execution status of 0 on a 1-255 correct errors
$ 1 $ 2 ... $ {10} - command script incoming data back to a space-delimited
$ # - the amount of statistical parameters passed $ {$ #}?
$ * - indicates that all mass participation, mass participation of all output as a string
$ @ - represents all the parameter passing, pass all the parameters output in the form of a list of
[the work to be performed for all transmission parameters when in operation, it is necessary to consider and $ @ $ *]

Variables defined format:
NAME = of VALUE (like a howl assignment, etc. howl Analyzing two)
we declare variables define the type of command to
declare -i integer int () STR ()
declare -a array
variable command:
1, underlined specify variables name
2, hump naming

4, test file test, condition determination
in the script, we need to make the statement branch; it plainly, they do judge
judge is to use the test command to achieve;
using the format:
1, test [the Option] File
2, [conditional statement]
[ when plus [] and when not to add []]?
common test options:
comparison options:
-eq equal
-ne not equal
-gt greater than
-ge greater than or equal
-lt less than
-le less than or equal
to determine options:
-f determine whether Common file
-d determines whether the directory file
-L determines whether the connection file
-r -w -x determines whether the file read and write execute permissions
associated options:
-o or
-a with
non!
string determination:
= both sides of the character is determined string is the same
! = not equal
-z string is determined whether the presence
-n -z and Rather, there is false, there is no true

5, logic operations
with &&: both sides of the commands are true, the result is true
or ||: both sides of the command, while true, is true, but false, is false
non =!

The logical operator command before and after docking is present alone;

[$ 0 -eq?] 0 && Exit Exit. 1 ||

6, the arithmetic operation
* the let. 1 +. 1
the let A =. 1 +. 1
echo $ A
expr. 1 *. 1
expr. 1 * 10
* $ [$. 1 + 10]
A = $ [2 +. 3]
echo $ A
$ (($. 1 / $ 2 ))
A = $ ((] 3/2))
echo $ A

+ - * / % **

Guess you like

Origin www.cnblogs.com/wangshilin/p/11365000.html