Create a script admin.shPerform the following functions:-H | --HELP: Providing Help information--add users: Completing user additions-del User | --delete: Complete User deletion-V: Turn on debug mode, display informationYou can use all of the above
in the In a Shell script, some operations that need to be reused are defined as public statement blocks, which can be called functionsWhat are the benefits of using functions? Make script code more concise, enhance readability and improve execution
Recently in the shell script, found some shell strings of the Sao operation, can improve efficiency.String Read
${var}: Value of variable var
${var-default}: If Var is not declared, the value of Var is $default
${var:-default}: If
Pipe character
| Function: The output of the preceding command is given to the following command job control
CTRL Z pauses a task
[[email protected] ~]# vim 1.txt [1]+ 已停止 vim 1.txt[[email protected] ~]# vim 2.txt [2]
First, the alarm system main script[[email protected] ~]# cd/usr/local/sbin/# #脚本基本都放在这个文件夹下, convenient management [[email protected] sbin]# mkdir mon## Create a monitoring script home directory [[[email protected] sbin]# CD mon[[email protected]
One, character interceptionExprBasic usageExpr substr $var 1 starting position for the length of the Intercept, such as:[Email protected] mnt]# a=centos6.9[Email protected] mnt]#[[email protected] mnt]# expr substr $a 1 6CentosCutBasic usage:Command
First, special symbols' * ' wildcard character, any of any characters'? ' any one character' # ' comment characters' \ ' de-semantic characters' | ' pipingThe prefix of the ' $ ' variable'!$ ' combination, regular inside means end'; ' multiple
Write a script in the Linux environmentFrom the keyboard to let the user enter several files, the script can archive this several files into a file:1. First introduce the CASE statement formatCase SWITCH invalue1)Statement...;;value2)Statement...;;*)
Customizing a function for printing function parameters[[email protected] shell]# vim fun1.sh#!/bin/bashpri(){ echo "第一个参数为 $1" echo "第二个参数为 $2" echo "文件名为 $0" echo "总共有$#个参数" }pri a b #调用函数Execution
1. The concept of variables: variables are stored in the program of the user's memory space, the variable name is the address of this memory space, the value of the variable is stored in the computer memory. Variable definition: It is simple to
8.1 Shell Introduction: Can be divided into interactive and batch processingInteractive: The user executes a command every input immediatelyBatch: The user writes the full shell script in advance, and the shell executes many commands of the script8.2
A variable in a shell script means that the command itself can represent a soft connectionShell variablesParentheses can only affect variables in parentheses because the parentheses open the child shellCurly braces affect variables outside the
1.FOR Loop structure 1.1 for loop structure syntaxGrammar:For variable name in variable Value listDoInstructions...DoneTip: In this structure, "in variable Value list" can be omitted, when omitted is equivalent to in "[email protected]", using for I
Java real-time program in the process of occasional abnormal information interruption in the case, through the shell script to complete the self-boot.The following is a shell script that monitors a real-time Java program.Determine if the program is
multiple values can be stored in an array. The Bash Shell supports only one-dimensional arrays (which do not support multidimensional arrays), and the subscript for array elements starts with 0. The Shell array is represented by parentheses, and the
This is a shell script practiced hand program that exercises the use of a for statement#! /bin/bashn=0while read arr[$n] #通过键盘给数组赋值 ... The first element of the array is saved in arr[0] ... Enter indicates the input interval for the element, ctrl-d
[TOC]Shell functions and arrays one, Shell function 1.1 function format 1function name { commands}Example 1:#! /bin/bashfunction inp(){ //定义一个inp的函数echo $1 $2 $3 $0 $# }inp 1 a 2 b //传入参数 //传入参数Run
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