First, use double brackets (()) to calculate#!/bin/bash#a=0for ((b=0; b; b++)); Do ((a=a+b)) // can also be written as a=$ ((a+b)) Done Echo $aSecond, seq, tr, sed, BC together to complete the calculation
for a list of the current path under the directory (not the list of directories) method, and share with you ~ ~1. Using ls-d with wildcard charactersls-d * * 2, ls-f with grep query with/end of the content-F: Displays the directory behind the/ls-f |
#!/bin/bash while:do neterror=$ (/bin/netstat-a | GREP-CW "close_wait") echo "Get TCP netstate ' LISTEN ' num ber cuccessful! " echo "Neterror" $neterror if [$neterror-gt "]; then echo" too much net Error,system would reboot
Tenth lineHow would you print just the 10th line of a file?For example, assume. has the file.txt following content:Line 1Line 2Line 3Line 4Line 5Line 6Line 7Line 8Line 9Line 10Your script should output the tenth line, which is:Line 10[Show hint]Hint:
1.4adding environment variables using functions1.4.1Introductionenvironment variables are typically used to store path lists, which are used to search for executables, library files, and so on. For example:$PATH,$ld_library_path, and they usually
Use Whil for if to print a prime number less than 100#!/bin/bash#author Alvin#version 1.0.0#test for 1-100 Zhishua=2While [$a-le 100];DoZ=1for ((j = 2; $j If [$ ($a% $j))-eq 0];thenZ=0BreakFiDoneIf [$z-eq 1];thenEcho-ne $a "\ T"FiLet A+=1Done2 3 5 7
If flow control:Conditional judgment statements in the shell are similar to other programming languages.If you need to know what the criteria are, you can get help with man testCommon formatsFormat Oneif condition; ThenStatementFiFormat Twoif
For loop:Used in the shell for looping. Similar to for in other programming languages, but somewhat different. The For loop is the most common syntax structure in bash.Common format Format OneFor variableDoStatementDoneFormat TwoFor variable in
While loop:Format OneWhile condition;DoStatementDoneFormat Two dead loopsWhile TrueDoStatementDoneFormat three dead LoopsWhile:DoStatementDoneFormat Four dead LoopsWhile [1]DoStatementDoneFormat Five Dead LoopsWhile [0]DoStatementDone****************
#!/bin/bash## 1, check whether the current user's identity has permissions# 2, check if there is a Yum source, if there is no need to create a Yum source configuration file# 3, install DHCP, if already installed, we can first remove and then install,
$0: The current script has a file name of $num:num 1-based number,$ $ is the first argument, and $ is the second argument, and ${is thetenth argument $#: The number of arguments passed in the script $* : All positional parameters (as a single string)
1. Shell FeaturesOrder history!! !$!n! characterTab key to complete file path or commandAlias a= "B" Unalias AWildcard * Matches 0 or more characters? Match one characterInput/Output redirection >,>>,,2>>Pipe characterJob Control CTRL + Z jobs FG BG2
This script parses the log of the Nginx load balancer:#!/bin/bashif [ $# -eq 0 ]; then echo "Error:please specify logfile. " EXIT0ELSELOG=$1FIIF[!-F$1] ; then echo "Sorry,sir. i cat ' T find this apache log file, pls try again! " exit 0
The default value in the shell is decimal, so how are binary, octal, and hexadecimal represented?Method 1: Use the prefix.0 begins with octal, and 0x starts with hexadecimal.As follows:#-----------------------------/chapter4/ex4-35.sh----------------
Today, when we look at the/etc/init.d/nginx script, we find that there is a lot of behavior in the script (the space name of the dot). For example, a few lines of file start:if [-r/etc/default/nginx]; Then
The feature of this series of blogs is--give the results of each orderOriginally wanted to write a good process, get a picture of what, but think online analysis too much, are better, so these blog even if it is a summary of their own it.#include
Several methods of shell script execution, shell scriptYou can execute shell scripts in the following ways:
1. The relative path method must be cd to the script path first.
[Root @ banking tmp] # cd/tmp [root @ banking tmp] #./ceshi. sh script
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.