Shell programming
################################################
Static language
Dynamic language
################################################
Programming languages: Machine language, assembly language, advanced languages
################################################
Object-Oriented programming language: SEHLL C
Object-Oriented programming language: JAVA Python perl C + +
################################################
Variables: Memory space, naming
Memory: Addressable storage unit
################################################
Variable type: Defines the storage format of the variable
Character type
Numeric type: integer, floating-point
################################################
Logical Operation:& with | | or! Non-XOR or
################################################
Bash Variable type
Environment variables
Local variables (local variables)
Positional variables
Special variables
Variable name rule
Cannot duplicate a variable that exists
See the name of the idea
################################################
Varname=value the entire bash process is working.
Local Varname=value valid for current code
Environment variables:
Current shell processes and child processes are valid
################################################
Undo Variable: Unset VARNAME
################################################
$? : Return value for program execution completion
o Correct
1-255 error return value 1, 2 127 reserved
[[Email protected] ~]# $?
-bash:127:command not found
[[email protected] ~]# echo $?
127
[Email protected] ~]# echo It is
It is
################################################
Output redirection
>
>>
2>
2>>
&> Errors and correct results
Give the return value to/dev/null
[Email protected] ~]# CD/CDD &>/dev/null
[[email protected] ~]# echo $?
1
[Email protected] ~]# CD/&>/dev/null
[[email protected]/]# echo $?
0
/dec/null
[[email protected] ~]# echo $?
0
commands for viewing environment variables
Printenv
Env
Export
################################################
What a script does: a command stack to accomplish a specific task
Scripting: Creating user1 user2 user3 user4 user5 users
##########
1. Create the. sh file
[Email protected]/]# vim/tmp/useradd.sh
##########
2, writing format
[Email protected]/]#
#!/bin/bash
#
Useradd user1
Useradd User2
Useradd User3
Useradd User4
Useradd User5
##########
3. Execute permissions for script
[Email protected] ~]# chmod +x/tmp/useradd.sh
##########
4, Execute script
[Email protected] ~]#/tmp/useradd.sh
################################################
Conditional judgment
How to achieve conditional judgment in bash
Condition test Type
Integer
Text
File
################################################
Conditional test Expression
[Expression]
[[Expression]]
Test expression
Integer comparison: Compare plus brackets
-eq: = equal [$a-eq $b]
-ne:\= Range
-gt:> Greater than
-lt:< less than
-gt:>=
-lt:<=
################################################
The logical key between commands
Logic and:&& the first one is false, the second does not have to be executed
|| The first one is true and the second one is to execute
Create User7, no presence created USER7, presence hint already exists
[Email protected] ~]# Vi./id.sh
#!/bin/bash
#
! ID user7 &>/dev/null && useradd User7 | | Echo ' User7 is exist '
Or: | | The first one is true
################################################
This article is from the "Jameszhan Linux Advanced ops" blog, so be sure to keep this source http://jameszhan.blog.51cto.com/10980469/1880110
Shell Programming Basics must know