The basis of each condition statement is to determine what is true or false. Whether or not you understand the working principle of the script will determine whether you are writing a quality script or a script that you will be proud.
Shell
Script
Operator
JavaScript has assignments, comparisons, arithmetic, bits, logic, strings, and special operators. This chapter describes the operators and some information about operator precedence.Table 2.1 A concise list of all the JavaScript
file Testing (-f,-d,-r,-r,...)
[-f/root/file.txt],[-d/root/mydir]
[[-f/root/file.txt]]File testing aspects [[]] same as []
string comparison (-z,-n,!=,==,...)
[-Z "${str}"],["${str}"! = "${str}"],[!-n "${str}"][] can only be
-B file if it exists and is a block special file, True-C file If it exists and is a character special file, True-D file if it exists and is a directory, true-e File is true if it exists-F file is true if it exists and is a rule file-G file is true
The data type is not allowed to change, which means that if you change the value of the numeric data type, the memory space will be redistributed.Python Numeric type conversionsint (x [, Base]) converts x to an integer long (x [, Base])
4. Input and output#! /bin/bash# Read users input and then get his nameread"Please input your first name: " firstNameread"Please input your last name: " lastNameecho-e"Your full name is: $firstName $lastName"Read usage:read[-ers][-a 数组][-d
Python escape characterPython uses a backslash (\) to escape characters when special characters are needed in characters. As the following table:
Escape Character
Description
\ (at end of line)
Line
Programmers with programming experience know the wording of conditional statements:Take C + + as an example:if (condition) { dosomething ();}The syntax for conditional judgments in Python is as follows:if (condition): dosomething ()So when is
VariableDefining variablesYour_name= "Runoob.com" #变量名和等号之间不能有空格Using variablesYour_name= "QINJX"Echo $your _nameEcho ${your_name}echo "I am good at ${skill}script"echo "I am good at ${skillscript}"Curly braces are added to help the interpreter
-b file If it exists and is a block special file, True-c file If it exists and is a character special file, True-d file if it exists and is a directory, true-e file if it exists, it is true-f file If it exists and is a rule file, True-if the file
The content of this section:1. Create a string2. accessing values in a string3. escape characters in a string4. String Operators5. string Formatting6. built-in functions for strings1. Create a stringvar1 = ' Hello world! ' VAR2 = "Chen71"2.
The string is the most commonly used data type in Python. We can use quotation marks (' or ') to create a string.Creating a string is simple, as long as you assign a value to the variable. Var1 = ' Hello world! ' var2 = "Python runoob" Python
I. Operator 1. Arithmetic Operator-$ a is used to take the negative value of $. $ A $ B adds the sum of $ a and $ B. $
I. Operator 1. Arithmetic Operator-$ a is used to take the negative value of $. $ A $ B adds the sum of $ a and $ B. The
If statement test condition. After the test condition returns true (0) or false (1), you can execute a series of statements accordingly. If statement structure is very useful for error checks. The format is:If condition 1Then command 1Elif condition
Seemingly simple things, in practical use, is still very interesting
arithmetic operatorsOperator name Result
$a + $b addition $a and $b and
$a-the difference between $b subtraction $a and $b
$a * $b multiplication $a and the product of $b
$a/$b
◆ Parameter description-B. returns true if the file exists and is a block file.-C: returns true if the file exists and is a character file.-D. If pathname exists and is a directory, true is returned.-E: returns true if the file or directory
Shell script checks the memcache process and automatically restartsRevised version:#! /Bin/sh# Check memcache process and restart if downMm_bin = "/usr/local/bin/memcached"Mm_log = "/home/xxx/memcached_check.log"Mm_ports = ("11211" "11212 ")Mm_param
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.