The simplest form of shell scripts is to list a series of commands. Shell acts as an interpreter and runs them one by one until the last or exits. However, this can only be a simple task. It is only the time when the province and province have to run commands one by one. To complete more responsible functions, add these things:
1. Control
What should I do if the preceding conditions are met? What should I d
Redirection, environment variables, and Shell functions of advanced shell script Programming
Shell is not limited to simply executing commands line by line. One of the more powerful functions is the ability to create functions and function libraries. You want to customize the command line interaction mode or automate file processing tasks. Consider using
This article is part (iv) of the Linux Shell Series tutorial, more on the Shell Tutorial: Linux Shell Series Tutorials
Like many programming languages, there are annotation symbols in the shell, and today we introduce the syntax and usage of annotations in the shell.
Co
1#!/bin/Bash2 ############################################3# @content Chapter8,9of Linux Command line and Shell Scripting Bible4 # @reader Gavin5# @date the/ A/ -6 ############################################7CHAPTER88 9+user varriable make the shell A-computer programTen 1when assigning a value to a user-defined variable, no spaces can appear One 2. Shell
Tags: shell shell variable date commandWhat is Shellshell?
Shell is a scripting languagecan use logical judgment, circular judgment and other statements;functions can be customized;A shell is a collection of system commands, such as a batch command of Windows;Shell
Shell scripts monitor MySQL services and shell scripts monitor mysqlThe main content of this article describes how to monitor whether the MySQL service is normal by using shell scripts. For more information, see
The general idea is to check whether the MySQL service is normal: Check whether port 3306 is started, ps to check whether the mysqld process is started,
The shell is much more programmatic in terms of programming than Windows batch processing, both in loops and operations.Bash supports one-dimensional arrays (which do not support multidimensional arrays) and does not limit the size of arrays. Similar to the C language, the subscript of an array element is numbered starting with 0. Gets the elements in the array to take advantage of subscript, the subscript can be an integer or an arithmetic expression
Basic shell syntax and shell syntax
I. Variables
1. Naming rules for variables: The name should start with a letter or underline followed by numbers, letters or underscores. It is best not to name it casually, so that you can see the variable name to guess its meaning.
2. Variable assignment: x = 100
Echo $ x
Delete variable: unset x
3. Braces are used to define the boundary of variable names.
[Root @ bogon
Use linux shell to automatically pin and linux shell to pin
If I post a post on the Forum to ask something, once the post fails, it will sink in seconds, but I really don't want to go to the top all the time. What should I do? The following shows how to use shell crontab to implement automatic top-up.
I will not talk much about it. Take Douban as an example --
Shell BASICS (3) -- quotation marks and shell basics -- quotation marks
--- Today, the space is relatively small; only quotation marks are introduced.
There are three types of quotation marks in shell: Double quotation marks ", single quotation marks", and reverse quotation marks'1. Double quotation marks: A character enclosed by double quotation marks. Except fo
2.shell Tools2.1. log filesBrief introductionIt is important to create a log file, which records important information. In the event of an error, this information is very useful for our troubleshooting, and the monitoring information can be logged to the log file.Common methods of log filesLog files identified by timeExample#!/bin/bash# the current date current_date= ' date ' +%y%m%d ' #今天的日志文件名todaylog = ' log/${current_date}.log ' #如果日志文件不存在, create
In the shell, arguments can be passed to a function when it is called. Inside the function body, the value of the parameter is obtained in the form of a $n, for example, $ $ for the first argument, and $ = for the second argument ...Examples of functions with parameters:
#!/bin/bash
Funwithparam () {
Echo "The value of the first parameter is $!"
Echo "The value of the second parameter is $!"
Echo "The value of the tenth parameter is $!"
Learn the first script from the shell, thanks to cloud Li Qiangqiang Teacher's shell programming tutorial
To create a shell script file:Touch menu.shTouch index.shTouch welcome.sh
To give the script file permission to execute:chmod a+x menu.sh index.sh welcome.sh
menu.sh
#!/bin/bash#menu.shfunctionmenu () {title= "myhome" name= "Randy" Time=
The operation of a numeric variable:
The numerical operation of the shell variable is mostly used in the process control of the script, in the shell environment, only a simple integer operation, does not support the fractional operation, the integer value operation mainly through the internal command expr execution. The following is the basic formatExpr variable 1 operator variable 2 [operator vari
1. Gets the return value of the Shell function call:#!/bin/sh info () { cat jlb.sh} res= ' info ' echo ' state: ' $?echo ' res: ' ${res}description : res='info' This behavior calls function info, which conforms to ' not single quotes, but the one below the ESC key, plus $? Returns the execution state of the previous command, is not a return value;2, get the return value of the shell command, the same
“#! Magic Number: The general specification at the beginning of the script, used to specify the interpreter to execute the contents of the script. Note: Only the first line of the script #! Valid, followed by a comment! If you do not specify an interpreter, the default shell execution script for the current system defaults to bash. Common example: #!/bin/bash #!/bin/sh# Note: Comments on the script, only for developers to see, the system cannot be tag
I have a Linux server at home and need to locate its IP address through the peanut Shell's DDNS. So create a script as follows to solve the problem of the recently appearing routing embedded device cannot DNS resolution, if you have the same needs as I do, welcome to this tutorial:1, the installation of Yum packageYum-y Install Curl2. Create a folder to store scriptsmkdir ~/script3. Create a domain name resolution scriptVim Editor ~/script/pusoray.shAdd the following content:#!/bin/bashdomain= "
First, the name of the variableThe variable name must begin with a letter or underscore, consisting of a letter, number, or underscore, and the variable name cannot exceed 255 characters in length.Ii. Classification of variables1. User-defined variables2. Environment variables3. Positional parameter variables4. Pre-defined variablesThird, user-defined variablesA user-defined variable is a "local variable" that can only take effect in the current shell1. Defining variablesVariable name = variable
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.