#!/bin/SHMyPath="/var/log/httpd/"MyFile="/var/log/httpd/access.log"#这里的-The x parameter determines whether the $mypath exists and has executable permissionsif[!-X"$myPath"]; Then mkdir "$myPath" fi#这里的-d parameter to determine if $mypath
Like other languages, the Shell can also contain external scripts. This makes it easy to encapsulate some common code as a standalone file.The Shell file contains the following syntax format:. FileName # Note number (.) With a space in the middle of
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
The test command in the shell is used to check if a condition is true, and it can be tested in three aspects of numeric, character, and file.
Numerical test
Parameters
Description
-eq
Equals is True
Data flow redirection is the transfer of a command that should appear on the screen to other places after executionStandard1, standard input (stdin): code 0, using or 2, standard output (stdout): Code is 1. , using > or >>3, standard error output
A test condition to judgeReturns a 0 exit state if the expression is true, or a non-0 exit state if the expression is false. Test has an alternative syntax, which is easier to read by enclosing the expression with parentheses "[]".1. string
some things to note about shell script:1, #这个符号是注释本行, usually used for annotations, #! Except that it is used to label which Shell executes this script,2, the order of execution from top to bottom, from the right3, ignoring blank lines, tab spaces4,
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
File judgment operator–b return True when file exists and is a block file-C Returns True when file exists and is a character-D returns True when pathname exists and is a directory-E Returns True when a file or directory specified by pathname is
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
Recently wrote a small program, need to use time. Traverse as part of a folder#!/bin/bashfor i in {1..30}dodate= ' date +%y/%m/%d-d "$i days Ago" ' Echo $datedoneFor loop, take the date of the recent n days.The core isDate= ' Date +%y/%m/%d-d ' $i
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,
Several possible causes:1 The user's home directory belongs to a group that has been renamed Root, and the solution uses root to perform Cd/home/;chown username:username username2 The user's home directory was modified, this time if you want to
1.shell IntroductionCommand line: The interface for the user to enter a command, which itself only accepts input and passes the command to the command interpreter.Shell:shell is a command interpreter and a program that provides a line-oriented,
$
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:
First look at the formatEcho-e "\033[word background color; text color m string \033[0m"ExampleEcho-e "\033[41;36m Font \033[0m"Where 41 of the position represents the background, 36 of the position is the color of the wordNote:1, the word
Ifs:A direct description of the usefulness of IFS, details of what ifs is doing ... Self GoogleFirst create a file of "a", and "a":Then we look at LS:--LSA a AIs this.Then if we need to write a script to manipulate each file:--For I in $ (LS); Do
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