1. What is a script
The shell script is actually a plain text document, we can edit this document, and then let this file Help us
Execute more than one instruction at a time, or achieve some specific functionality.
To install a certain logical relationship records the documents explicitly
In the case where the file has executable permissions, the file name can be used in the script to record the explicit execution
The shell script is an explanatory form language, and the actions recorded within the file require an interpreter shell
2. How to create a shell script
1)
Vim test.sh
#一般情况下脚本的结尾为". Sh" is not system-defined, but is an industry-standard
2)
#!/bin/bash
#脚本头的写法, this is the interpreter used by the script and the child shell that is opened when the default script is run.
3)
Script content is made up of explicit and explicit logical relationships
4)
?? ? How the script executes
Method One:
?? ? SH script Name
Method Two:
?? ? chmod +x Script
?? ? Script Name Call
[Email protected] mnt]# vim test.sh
#!/usr/bin/env Bash???? Different system locations
3. Scripting Specifications
1) scripts should be added to the script description information
Author?? ??? ?: Lee
Email?? ??? ?: [Email protected]
Create_date?? ?: 2017-08-21
Vesion?? ??? ?: 1.0
Description?? ?: Test Scripts
2) Try not to use Chinese in the script, even if you use pinyin instead
3) The script appears in the () | []| {}|<> wait for the symbol to appear once, and
The characters in the content should have spaces with these symbols
4) The statements in the script should be finished at once in rich content
5) The action used in the statement is indented to write, making the script easy to read
6) How to enable Vim to automatically add script instructions
Map <F4> ms:call addtile () <cr> ' s?? ? # #设定快捷键
function Addtile ()?? ??? ??? ? # #设定函数内容
??????? Call Append (0, "# Author????????: Lee")
??????? Call Append (1, "# email?????????: [email protected]")
??????? Call Append (2, "# Version???????:")
??????? Call Append (3, "# Create_date???:". Strftime ("%y-%m-%d"). " #")
??????? Call Append (4, "# Description???:")
Endfunction
4. Variables
1) Function: Used to invoke a value, or a character.
2) naming rules for variables:
The first letter cannot be a number
The variable can contain only alphanumeric and "_"
TEST
Test_redhat
Test_redhat
Testredhat
5. Translation and annotation of special symbols
\?? ? translate a single character
‘ ‘?? ? Strong references
" "?? ? A weak reference to its translation function cannot be translated "!" "$" "\" "`"
Example script implementation: Will/var/.log? /mnt/2017_12_11
[Email protected] mnt]# vim backup.sh? Edit Script Content
Test:
Preliminary understanding of Linux-shell scripts Script