1) Start specifying the script interpreter#!/bin/sh; #!/bin/bash2) opening plus version and copyright information3) No Chinese comments in script4) file saved with. sh extension5) Full-time write-in of paired content to prevent leakage6) [] have spaces at both ends of the brackets7) Process Control statements are completed once, then add statementsHint: You check the script clearly no problem, but is to perform a baffling error, to think of executing the Dos2unix commandGood habit: Each executio
In shell programming, operators are essential, and can be said to be used in every script. Familiarity with mastering operators is a basic skill.
Comparison operators:
eq
Equals
Ne
Not equal to
Lt
Less than
Le
Less than or equal
Gt
Greater than
Ge
Greater than or equal
instruction (displays the exit status of the last command. 0 means no error, any other value indicates an error)$-shows the current options used by the shell, same as the SET command function[email protected] is similar to $*, but can be used as an array--------------------------------------------------------------------------------------------------#!/bin/sh##############Export lang= "ZH_CN. GB18030 "Export JAVA_HOME=/USR/LOCAL/JDKExport path= $JAVA
program exit representative (typically 0 for execution success, not 0 for execution failure)echo $?--$# represents the number of arguments for the current shell--$* (an entire string) [email protected] (each parameter counts as a string) represents all parameters--$$ PID of the current processCustom variables--The syntax format is: Name=[value]--Note:Variable equals cannot have spaces on either sideVariable is case sensitive--Use ($ variable name) to
Ten$GLOBIGNORE
A list of pattern matches for a file name, and if the file matched in the wildcard (globbing) contains a file in the list, the file will be removed from the matching result.
$GROUPS
This is a list of group IDs (arrays) for the current user, as is the content recorded in the /etc/passwd file.
Eleven$HOME
User's home directory
Twelve
$HOSTNAME
("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>Method Two: seq is a fixed notationIdea: 1. First define a variable i2. Let the value of sum first start with the value of 0,i from 1 to 1001.3. Let I equals a number to remove to 2 if equal to 0, is the number we want to let them add together can get the sum neededVim sum2.sh#/bin/bash#written by Lizheng#about sumLet sum=0For I in $ (seq 1 100); DoIf [$[$i%2] = = 0]; ThenLet sum+= $iFiDon
Shell echo CommandDisplay Normal string:echo "I am cat_crazy."Note: The double quotes here can be omittedShow escape characters:If you want to output quotes, the * number needs to be escaped to output, as followsecho \ "I am cat_crazy\"The output is "I'm cat_crazy."Note: Quotes need to be escaped to outputDisplay variables:Name= "Cat_crazy"Echo $nameShow line breaks:Echo-e "Hello \ n" #-e open escape \ n line breakecho "Cat_crazy"The output is:HelloCa
sundo Echo ' Today is $var 1 ' donefor var2 in {1..10..2}doecho ' this is $var 2 "Donefor Var3 in $ (SEQ 1 2) Doecho" I had a/an $var 3 "Donefor VAR4 in $ (LS) Doecho" Here's the file $var 4 "doneWhile loop#!/bin/bashi=1while ((I SELECT statementThis SELECT statement to the time the wood has seen, run when you can interact with the user, run the following program to understand. If you don't break it, you're going to die.#!/bin/bashecho "which color do you like?" Select Var1 in red Green Bluedoe
.$: Contains the text content of the first field.awk ' {print $} ' filename prints the fifth column.Print permissions and file names for files in the current directory:awk ' {print $ ': ' $9} 'Total-rw-rw-r--.: BsdmakefileDrwxrwxr-x.:config-rw-rw-r--.: config.inDrwxrwxr-x.:d OCSDrwxrwxr-x.:feeds-rw-rw-r--.: Feeds.conf.defaultTo remove a sentence that contains a word in a file:Sed ' s/[^.] *mobile phone[^.] *\ . G ' filenameRemove the sentence that contains the word "mobile phone".The format of t
Fgrep. These return values make it possible to perform aself-initiated text processing. I used the Egrep tool in the example above. is the extension of grep, a lot of other ways to use this tool and the above introductionSome of the inadequate places you can go to the encyclopedia to find out, in fact, some of the more advanced tools also support this expression. I'll be in the knot.The blog is again introduced.I personally think that the rote of these characters is inappropriate. We should le
Integer two-dollar comparison operator
The comparer used in [] and test
The comparer used in (()) and [[]]
Description
-eq
= = or =
Equal abbreviations, equal
-ne
!=
Not equal abbreviations, unequal
-gt
>
Greater than greater than
-ge
>=
Greater than or equal to greater equal
-lt
Less than than similar
-le
Less than or equal to
Tags: ret strong expr pts null. sh com bin filedetermine whether a variable is an integer through expr[email protected] scripts]# cat judge.sh#!/bin/bash############################################################### File Name:judge.sh# version:v1.0# Author:rain Jin# Blog site:http://www.cnblogs.com/rainjin/# Created Time:2017-10-27 21:19:42# Environment:centos 7.2 kernal 3.10.0###############################################################judging If the arguments you have entered is integers;If
Tags: Linux shell1.1 The following table is a common two-dimensional comparison operatorWe can also see through the man testTips(1) The "(2) the ">" symbol is greater than the meaning, if[["$a" > "$b"]], if[["$a" \> "$b"]. You need to escape in parentheses because the shell is also redirected with (3) The "=" symbol equals the meaning, if[["$a" = "$b"]],if[["$a" = "$b"]. Escaping is not required in single [].Special tips:"=" and "! = "use in [] does n
1.1 String test operatorThe string test operator has the function of comparing whether two strings are the same, whether the length of a string is zero, whether the string is null (NOTE: Bash distinguishes between 0-length strings and empty strings, etc.)The following table is a common string operatorYou can also view the string test operator with the man testString test operator Hints:(1)-N compares whether the string length is nonzero, or true if nonzero: [-n ' $myvar](2)-Z compares whether st
Compare days with 2 dates1. Script referenceScript 1:
#!/bin/bash#格式化过期日期,格式化过期日期完整时间以当前时间作为参考!expday="2018-04-11 `date +%T`"echo "Expire day is $expday"#当前日期时间格式为stamp时间戳todays=`date +%s`echo "Today is $(date +"%F %T")"#以下2种方式做时间的四则运算,分别使用 let 或者 $(( ))#过期日期已格式化,规避整数运算的误差(去余数)#let dayDiff=($(date -d "$expday" +%s)-$todays)/86400dayDiff=$(( ($(date -d "$expday" +%s)-$todays)/86400 ))echo "Diff day is $dayDiff days!"Other Notes:Bash does not support floating-point operations, and if floatin
Previous Edit CommandA: Append data after the current cursorO: The next line of the cursor inserts dataDW Delete a Wordd$ Delete to end of lineDD: Delete Row, 5dd delete 5 rowsThe use of backspace and delete keys in normal mode is not recognized.10.1.4 Copy and pasteDD can be pasted with p after deletion.The copy command is Y,YW copy a wordy$ Copy to end of lineThen use p to paste10.1.5 Find Replacement: s/old/new/g a line command to replace all old, which is replaced only on one line: N,ms/old
fileYou can also connect many parameters.such as Sort-t ': '-K 3 testYou can think of it as something inside. xxx1:xxx2:xxx3:xxx4:xxx5means to sort the xxx3-T: Specifies a character to distinguish the key position-K:--key=pos1[pos1]. The sort starts with pos1, and if POS2 is specified, it ends at Pos2.| Redirects the output of the du command to the sort command.-r: Indicates descending order.Here is an example:4.3.21. grep [options] pattern [file]For example:grep t test//Search for text in test
ifMulti-branch statement practice#!/bin/bashread-p " Please enter 100 m running seconds: "IIf [$i-lt] [$i-GT 0]Thenecho " Enter the final "read-p " enter male and female "aif [$a = male]Thenecho " into the men's group "elif [$a = female]Thenecho " Enter the women's group "Elseecho "Error"Fielif [$i-ge 10]; Thenecho " elimination "Elseecho " Error "Fi Case Statement Practice, automatically unzip the compressed file according to the filename suffixVim untar.sh#!/bin/bashCase $ in*.gz)If [-F $]Th
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.