Exercise 1:Print a line with only one numberRequirements: title, a text document with only a number of lines to print outReference Answer:#!/bin/bash# date:2018 March 16 f=/etc/groupline= ' wc-l $f |awk ' {print $} ' for L in ' seq 1 $line ' do n= '
method One: Switch toShellthe directory where the script is located (at this time, called the working directory) executesShellScript:Cd/data/shell./hello.shThe./ means to execute hello.sh under the current working directory . If you do not add
Pstree-p #显示进程编号 (tree) echo $$ basic structure of #显示当前shell进程编号 scripts: #! Shebang (indicates what shell is used to open a file, typically using bash) configuration_variables #定义变量FUNCTION_DEFINITIONS # define function Main_code #主要执行命令
function definition Format:It's a bit like JS, but the function keyword is optional in the shell.Such as:sum{ //Shell statement} function sum () { //Shell statement}Function Call Method:Sum parameter 1 parameter 2 ... Get function Parameters:
DirectoryI. Condition selection: If statementTwo. Conditional judgment: Case statementThree. For loopI. Condition selection: If statement
Single Branchif judgment condition; thenBranch code with true conditionFiExample: Judging whether a number
Exercise 1:Statistics Log size If we need to execute the script you wrote every hour. In the script to implement such a function, when the time is 0 and 12 points, you need to empty the file under directory/data/log/, notice can only empty the
Title requirements:Write a script to enter personal information/root/bin/information.sh, the requirements are as follows:1. Prompt the user to enter username (need to check the name of the character, the user name can not be blurred contains any of
Exercise 1:Enter a number to execute the corresponding commandRequirements: Enter a number and then run one of the corresponding commands. The commands shown are as follows: *cmd meau* 1-date 2–ls 3–who 4–pwd; when input 1 o'clock, run date, enter 2
1. PurposeCopy all files larger than 1M (customizable) in the/root directory to the/tmp/bakdir (customizable) directory, and you need to keep the directory structure.For example, the/root/reed.file file size is 12M and will be copied to
Routine maintenance requires a generic execution shell, but the CentOS 6 version is different from the 7 version of the command, and needs to be judged by the program itself, as follows:1. View cat/etc/centos-release[Email protected]/0 #
Exercise 1:Delete the letters in the textRequirements: Delete the line containing the letters in the first 5 lines of a text document and delete all the letters from 6 to 10 lines (file 1.txt, lines greater than 10 lines)Reference Answer:#!/bin/bash#
Nginx log will increase with the amount of traffic, the larger log will affect the analysis log when the analysis and processing, we can use the shell to the Nginx log timing segmentation, to weeks or days, for a long time log can be deleted
Crontab can execute a shell script and execute a series of Linux commands at a specified timeExample: Server administrator regularly backs up database data, logs, etc.DetailedCommon commands:Crontab–e //Modify the crontab file, if the file does
First the CD into a directoryTauch tset.sh//Create a new test.sh fileVim test.sh Edit ScriptI insert#!/bin/bashDataPress the ESC keyThen press CTRL +:Wq + EnterLs-l test.sh//view file permissions-rw-rw-r--1 Elasticsearch elasticsearch 18 February 8 1
1. Variable assignment:NAME=LBG equals sign cannot have spaces name= "Lebron James" variable values have spaces in double quotes Echo ${name} with ${} More insurance shopt-s-O Nou Nset setting "Declare and use first"2. Cancel the variable:unset
The first line of the shell script illustrates the path to the interpreter: #!/bin/bashRun the script two ways: Use the bash command to run the shell file, or grant the script file execution permissions, you can directly execute the fileWhen the
Summary
The attribute of an array is a set of identical data types, although the shell is a weak type, but we can also divide its array into 数据类型的数组 字符串类型的数组 two categoriesSeparating the shell array elements from each other 空格
$0, $? In Shell scripts? , $! , $, $ *, $ #, $ @, Etc.
$0 indicates the execution name of the program. The file name of the current script $ n indicates the nth parameter value of the program. n = 1 .. 9 $ * all parameters of this program. This
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service