Shell Script Learning (i)A) Introduction to code-style shell scripts 1. Download Xshell 5 Build a folder Mkdri Home/data;1) Look at a 1.sh built in data See if the build was successful.2) and edit echo Hello Word, and save the launch
1. VariablesA: Define variable a=1, only valid for your shell processB: Define the variable export b=1, which will take effect on your shell process and its child processesC: Variables defined in the script.sh script, when source script.sh is in the
#!/bin/bashWhile:Doecho "1. View CPU
View Memory
View Disk
View IP
Exit
Read-p "Please select menu:" ItemIf [${item}-eq 1]; Thenecho "CPU operating frequency is as follows:"Cat/proc/cpuinfo | grep MHRead-p "Enter carriage
1. Two methods of setting login prompt(1)/ETC/MOTD[[email protected] thzzc]# echo this is THZZC test Linux >/ETC/MOTD[Email protected] thzzc]# CAT/ETC/MOTDThis is THZZC test Linux(2)/ETC/PROFILE.D[Email protected] home]# echo echo This is THZZC
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]
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
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...;;*)
First, Shell introduction1, the shell is a command interpreter, providing users and machines to interact, each user can have their own specific shell,2, CentOS7 default shell for bash, and Zsh,ksh they have the difference in detail,We can check if
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
Judging command testYou can use the test command to perform tests on files, strings, and so on, typically with control statements such as While,if,case"字符串测试" ? test str1==str2 测试字符串是否相等 ? test str1!-str2 测试字符串是否不相等 ? test str1 测试字符串是否不为空 ? test -n
Shell Common Regular ExpressionsCommon Regular expression ^ # line Header locates $ # end of row. # match any character except line break * # match 0 or more repeating characters + # Repeat once or more? # repeat 0
I. Historical order History #查看历史命令 history-c #清空历史命令 history-w #不等退出, write the history command in the cache directly to the history command to save the file ~/.bash_history vim/etc/profile #默认历史命令保存1000条, can be modified histsize save the
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