5.3 Shell Programming 2Condition Judgment:If the user does not existAdd user, give password and show add successOtherwiseDisplays if it already exists, does not addHow do I make conditional judgments in bash?Condition Test Type:Integer testCharacter
One, branch control statements1. If: Fi conditionif condition; ThenActionFi2. If: else.. Fi conditionIf Condition;thenActionElseActionFi3. If: else if: else.. Fi conditionIf Condition;thenActionelse if Condition;thenActionElseActionFiNote: If and
First name the shell command as a. sh fileSave the above code as test.sh. and CD to the corresponding folder:chmod +x./test.sh #使脚本具有运行权限./test.sh #运行脚本Assuming an error/bin/bash^m:bad interpreter:no such file or directoryOne of the reasons for
1. Separate each command;Note: The execution of each command will not affect the execution of other commands. In other words, each command executes,However, there is no guarantee that each command will execute successfully.2. Separate && between
“#! 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
Problem: Now there are two scripts, I want to match the contents of File1 by File2[email protected] home]# cat file13-1-1 potv=1,pota=0,potp=21-4-76 potv=1,pota=0,potp=12-1-2 potv=1,pota=1,potp= 13-1-4 potv=1,pota=1,potp=24-1-5 potv=1,pota=1,potp=27-
Parameter unwinding (parameter expansion) is the procedure that the shell uses to provide variable values in a program.Expansion operators include substitution operators and pattern matching operatorsSubstitution operators
Operator
In general, most shell command windows, such as Python,scala, some non-relational database, and so on can be ctrl+d or ctrl+z,ctrl+c exit, this is the most effective way.If you do not use the above mandatory exit command, you can also use quit,exit,
$
File name of the current script
$n
N is a 1-based number, which represents the first argument, and $ $ for the second argument, and ${10} for the tenth argument
$*
All positional parameters (all
Tag: Folder file exists and dir file directory parameter is judged#shell判断文件夹是否存在 # If the folder does not exist, create a folder if [!-D "/myfolder"]; Then Mkdir/myfolderfi#shell determine the file, whether the directory exists or has permissions
String slices:${var:offset:number}Offset: The number of strings to skipNumber: The string to be fetchedCases:Name= "Obama"${name:1:2}--Displays the result as Ba${name:1}--Displays the result as BamaTake the rightmost few characters of the string:
One: RANDOMEcho $RANDOMRandom number is a range of 1--32767, generally used it can be cracked1.2 Generate a eight-digit random password:echo $ (($RANDOM +11111111))Two: Md5sum random encryption method generates a longer passwordTake 9-digit password:
Due to the need to manually install SBT for the first time, networking is required, so the network adapter mode of the virtual machine is set to "bridge mode" so that it can be connected to the Internet.However, when the "Spark-shell--master
Linux task ManagementThere are two types of task management under Linux , each of which is one-time and periodic . Disposable is at and the Batch, periodicity is divided into the system regardless of what and user tasks .Disposable Tasks :1.
from Import Models class Person (models. Model): = models. Charfield (max_length=30) = models. Integerfield () def__unicode__(self): # Use the Def __str__ (self) return self.name in Python3$python manage.py Shell>>>from
First, Background introductionDBA Daily Update Insert|update More, delay a lot of time. The development of tools, although the user password in the script encryption and strict operation, but carefully query internal logic or may reveal the password,
2.1.1 Parameters for shell scriptsCommon parameters(1) * A string to display the parameters passed to the script, and the location variable, this parameter can be more than 9(2) @ start at parameter 1, show all parameters passed to the script, and
Summary of Common shell commandsThis article summarizes some of the common shell commands, hoping that Linux small white like me in the familiar with these commands, can basically cope with the small white phase encountered problems1.cdAfter the CD
Type of shell
View the shell program used by the user, the Seventh field in the/etc/passwd file (as if it were the last one, mainly the bash shell)
There is also a default shell of/bin/sh, which acts as the default system shell for
Several Methods for executing shell
This section describes four methods for python to execute shell commands:
1. the OS. system () function in the OS module executes shell commands.
Note: This method cannot be output by shell commands.
2. popen ()
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