sudo equivalent to root permission execution commandGive executable permissions to all user files: chmod a+x script.shExecute script:./script.sh#./represents the current directoryCommand 1:echo "Welcome to Bash"Command 2:printf "Hello
Reading slow, easy to forget, on the Internet to find examples to do, pondering the examples do not understand, and then continue to Baidu.The importance of shell scripts under Linux is not much to say. Starting with the first example:#!/bin/"Hello
Bo main name: Li ChangmingBlog Address: http://keep88.blog.51cto.comThis note is from the old boy books: Learn Linux OPS Shell programming with old boysSpecial extension variables1. ${parameter:-word} Functional PracticeThe role of ${parameter:-word}
One: Shell introduction1. What is a shellThe Shell's Chinese meaning is "shell," in layman's words, the shell is an interactive programming interface that uses the user input to drive the operating system kernel to complete the specified work. In
Shell programming is in the form of:1: meta-character []. * ?+ ( ) | { } ^ $2: [a-z0-9] Represents a random number and letter match3: [^a-z] matches the random one except the letter4:ab+c + represents a character that matches one or more of the
Alias creating aliasesUnalias Deleting aliasestype [name] to see if it is an internal or external commandenv lists all environment variables and their contents in the current shell environmentset to observe all variables in the current shell
Shell BasicsFirst, the variables in bash1, the definition of the variable: The variable is the memory unit of the computer, where the stored value can be changed.2, the variable's setting rule: The variable name cannot begin with the number, the
The Shell implements a simple calculator function with the following script:[[email protected] scripts]# Cat Jisuan.sh#!/bin/bashprint_usage () {printf $ "usage:$0 NUM1 {+|-|*|/} num2\n" Exit 1} #判断传入的参数是不是3个if [$#-ne 3] then print_usagefifirstnum=$1
Shell's sed command to delete a variable with a "date time and so on" methodThe SED command deletes the specified content and may be known, for example, if you want to delete the line containing "Badboy" in a file, use the following command directly:
Vi/etc/logrotate.d/nginx #编辑脚本/usr/local/nginx/logs/*.log/usr/local/nginx/logs/nginx_logs/*.log{Missingok # ignores errors, such as "log file cannot be found" error message. Dateext # The log file after the switch is appended with the date of the
The read command is used to receive input from the keyboard's standard input and other files, and after the input is entered, the Read command places the data in a standard variable.Example 1:#!/bin/bashRead-s-P "Enter you password:" Password #-s:
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:
Shell Scripting Features:Connect MySQL, create the database automatically, the script is as followsMysql-h$mysql_ip-u$mysql_user-p$mysql_password--default-character-set=utf8-e "CREATE database IF not EXISTS test"Database IP, user, password using
First line: #!/bin/bash--#! Interpreter for Tag scriptScript: #!/bin/bashecho "Hello World"Give execute permission chmod +x./test.shExecute script:./test.shThe $ symbol is not required when defining a variable: td= ' Date ' +%y%m%d '1. There can be
For Shell scripting features it isProgramming languages, script type languages, interpreted languages.There are always three execution structures to follow when writing scripts: sequential execution of structures, selection of execution structures,
Today, a friend suddenly asked me in the shell, how to compare floating point and integer, but I asked a Leng, in the work did not encounter this scene. We also know that the calculation of numbers in the shell is usually converted to integers, such
Cat: View the contents of a file, connect a file, create one or more files, and redirect output to a terminal or file usage: cat [options] [file]1. $ Cat Hello.txtdisplaying content in a hello.txt text file2. $ cat-n File-N option to display the
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