I. Logical judgments in shell scriptsIn the shell script, many will logically judge, judge a certain value, judge a file, or a directory, we do some action against the result of the judgment, if there is no judgment, there is no way to do some
I. Logical judgments in shell scriptsGrammar1. Format 1if condition; Then statement; FiExample: If a is greater than 3, print OK[[email protected] ~]# vi 2.sh[[email protected] ~]# bash -v 2.sh #!/bin/basha=5if [ $a -gt 3 ]then 2. Format 2if
20.5 logical judgments in shell scriptsYou should use a variable instead when you use a string more frequently in your script and the string length is longWhen using conditional statements, variables are often used?? If [$a-gt 1]; Then ...; FiWhen
What is a shell?The shell is a scripting language aming_linux blog.lishiming.netYou can use logical judgments, loops, and other syntaxFunctions can be custom-definedThe shell is a collection of system commandsShell scripts enable automated
1. Open the terminal and enter the help command to see a list of the built-in shell commands for the system's default shell (usually bash):[[Email protected] ~]$ help GNU bash, version4.1.2(1)-release (x86_64-redhat-linux-GNU) These shell commands
If condition test Type: File test, digital test, string testIf statement structure:
If ...; Then ...; Fi
If ...; Then ...; else ...; Fi
Conditional test expression:
[Expression]
Local variables in shell scripts define functions in the shell to make the code modular and easy to reuse code. But the scope of the variables and functions of the script itself can be confusing, and here's a look at the problem. (1)The variables
Conditional judgment in shell programmingConditionsIf-thenCaseIf-thenSingle conditionif commandThenCommandsFiWhen the command return code is 0 o'clock, the condition is setif.sh#! /bin/Bashif Date Then Echo "command EXEC"fiifdate123 Then
Digital time Transfer Standard Time:Digital time such as: 20151009163000Standard Time: 2015-10-19-16:30:00A= ' head-1/home/xxx/xxx/bin/.status |awk-f= ' {print $ {} ' |sed-r ' s/([0-9]{4}) ([0-9]{2}) ([0-9]{2}) ([0-9]{2}) ([}) ([0-9]{2}] ) ([0-9]{2})
Logical judgments in shell scriptsIf logic is judged. The basic syntax for if judgment in the shell is:1) without ElseIf judgment statement; then COMMANDFIFor example:[email protected] sbin]# cat if1.sh#! /bin/bashread-p "Please input your score:
Transfer from http://blog.csdn.net/wangtaoking1/article/details/9838571 The main record is the concurrency and serial execution of commands in the shell script.By default, the commands in the shell script are executed serially, and must wait until
For automated operations, such as backup recovery, DBAs often need to encapsulate SQL statements into shell scripts. This paper describes several methods of SQL statements for shell scripts in MySQL database under Linux environment, for your
echo Display in shell script with color display, echo display with color, need to use parameter-EThe format is as follows:Echo-e "\033[word background color; text color m string \033[0m"Example: Echo-e "\033[41;36m something here \033[0m"Where 41 of
Shell Script Introduction
Shell is a scripting language
You can use logical judgments, loops, and other syntax
Functions can be custom-defined
The shell is a collection of system commands
Shell scripts enable automated
Shell Script Introduction
Shell is a scripting language
The shell has its own syntax, and can use logical judgments, loops, and so on.
Functions can be customized to reduce duplicate code
The shell is a collection
Quotes in shell
1. Double quotation marks
$, ', \, Retain special meaning
Note that escape characters such as \ n are not supported by default when echo is not added.
Supported by printf
[Root @ Centos5 test] # echo "\ n"
\ N
[Root @ Centos5 test]
In shell, the $ {} truncation function $ {file *}: removes the first string and its left string: dir1dir2dir3myfiletxt $ {file *}: removes the last string and its left string: myfiletxt $ {file *}: remove $ {} in the first and left shells.
Shell quotes 1. double quotation marks $, ', \, reserved for special purpose. Note that [root @ Centos5test] # echo & quot; \ n & quot; is supported by the escape character "\ n" by default when echo is not added; \ n [root @ Centos5test] # [root @
Syntax of the common read command in Shell: [python] read-p & quot; Prompt & quot; variable1variable2variableN-p & quot; Prompt & quot ;: display prompt information (displayed in the same line as the user input) variable1: The first value that the
How do I get a number in shell? -- Linux general technology-Linux programming and kernel information. The following is a detailed description. [I = s] This post was last edited by Growth MB
For example:
Note: Please change the content here in
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.