Mainly includes the following 3String manipulationMathematical operationsFloating point ArithmeticOne. String manipulationConnection of StringsConnection Word 2 strings do not need any connectors, write next to each otherLength acquisition Expr
One of the requirements of the project: to prevent the script from repeating the schedule, causing the simultaneous runtime to conflict with each other, you need to create a file before the script runs and delete it at the end. When the script
Special variables:$?: The execution result of the previous command returns a value of 0-255,0 for execution success, and other values indicate unsuccessful execution$!:shell PID of the last running background processPID of the $$:shell itself$:
Create a shell with a case statement (function is open, close, reset, display virtual machine)#!/bin/bashCase "$" inStart)/* When the keyword is start, execute the statement that opens the virtual machineecho Start ...Virsh Start $
$? Represents the return value for executing the previous command: If 0 means execution succeeds, non 0 means execution fails$, $ 、。。。 Represents the parameter 1, parameter 2, respectively 、。。。$# indicates the number of parameters for this program$*/
Echo is an internal command of the shell that prints the specified string on the screen. Command format:
Echo Arg
You can use echo to achieve more complex output format control.Show escape characters
echo "\"It is a test\ ""
IntroducedFind命令的工作方式:沿着文件层次结构向下遍历,匹配符合条件的文件,并执行相应的操作。Options-print: Indicates the file name (path) to print out the matching file. When using-print, ' \ n ' as the delimiter used to separate files-print0: Indicates that each matching file name is
Linux Shell intercepts strings
There are many ways to intercept strings in the shell${var#*/}${var##*/}${var%/*}${var%%/*}${var:start:len}${var:start}${var:0-start : Len}${var:0-start}
Here are a few examples to illustrate:1) Get the
A function is the name of a command or a set of commands.
Functions can make the program modular, thus improving efficiency.
The shell stores functions in memory rather than in disk files, so accessing the function is much faster than accessing
1, command substitution: 'Inverted single quotes, also called heavy notes. On the keyboard and the ~ key together of the key yo, do not knock into single quotation marks.AAfter using ", the shell first replaces the date command enclosed in the
Linux+shell Administrator's Good helper--batch decompressionRecently, the company has been busy with OA on-line work, as an administrator, it is necessary to provide them with data backup and recovery operations, the main operation is to restore the
-eq equals-ne Not equal to-GT Greater than-lt less than-le less than or equal to-ge greater than or equal to-Z Empty string= Two characters equal! = Two characters are not equal-N Non-empty stringStrings are commonly used to check user input,
In a Linux system, you can use FDISK to partition the hard disk, but to manually execute a lot of commands, it is cumbersome to use, and now remember that a script with Fdisk is automatically executed.1 #make Partition2Ddif=/dev/zero OF=/DEV/MMCBLK1
The shell script obtains a method for each CPU usage of the host.#!/bin/Bashinterval=3Cpu_num=`Cat/proc/Stat|grepcpu[0-9] -C ' Start_idle=() Start_total=() cpu_rate=() Cpu_rate_file=./`hostname' _cpu_rate.csvif[-F ${cpu_rate_file}]; Then
1. Shell Script ProgramThe shell is the "shell" of the operating system, and the shell provides users with a human-computer interface. All the user's actions on the computer and the data that the computer obtains are managed by the shell.Shell
Shell scripting is an essential skill for Linux OPS engineers and a very important skill, so it's only good to learn shell programming well. Basic grammar I will not speak, learn the C language of these languages, a little bit to understand the
Suppose we define a variable as:File=/dir1/dir2/dir3/my.file.txtWe can replace each other with ${} to get different values:${file#*/}: Take out the first/its left string: dir1/dir2/dir3/my.file.txt${file##*/}: Take out the last/and left string:
functions: Function functions are statement blocks consisting of several shell commands for code reuse and modular programming1) Definition of function:Can be defined in the command line, part of the script, only in a separate file of the
Array of shell scripts and Yum "Down"ArrayVariables: Storing the memory space of a single elementArray: A contiguous memory space that stores multiple elements, equivalent to a collection of multiple variables.Array name and IndexIndex: Numbering
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.