ENGINEER1.4Shell Script BasicsUnderstanding the shell environmentHow bash shells are usedInteractive:--manual intervention, high degree of intelligence----explain execution by article, low efficiencyNon-interactive:-Need to design in advance, the difficulty of intelligence is big;--Batch execution, high efficiency;-Easy to implement in the background and quietly;What is Shell
"! -name "DB"! -name "rtx*" ' ">>/shell/bAckup.logElseecho "' Date +%y%m%d ' Delete unsuccessful" >>/shell/backup.logFi# from Email adminMail-s "DataBackup" [email protected] If [$WEEK-ne 0];thenif [!-d/hddf/database/' Date +%y%m%d '];thenMkdir-p/hddf/database/' Date +%y%m%d 'mv/hddf/database/{*.bak,*. BAK}/hddf/database/' Date +%y%m%d '/FiElseecho "Today is Sunday no data backup" >>/
-5.1.29.jar;. /lib/match.jar Com.test.web.MatchShell script:/usr/java/jdk1.6.0_32/bin/java-xms512m-xmx512m-xx:newratio=3-classpath./match.jar:./ Mysql-connector-java-5.1.29.jar Com.test.web.MatchWhere the bat file differs from the shell script in that the JDK is located on a different path. \jdk1.6.0\bin specifying the JDK path-xms512m-xmx512m-xx:newratio=3 Configuring memory to run the current script-classpath.;. /lib/mysql-connector-java-5.1.29.jar;
\u indicates that the current user name \h represents the machine name \w represents the base name of the current working directory \w represents the full path to the current working directory. $, $, $, $: $ The name of this shell file refers to the first one passed to the shell program The parameter "$" refers to the second parameter, "$" refers to the third parameter $# the number of arguments in the
parameter$n is the nth parameter"[Email protected]" was expanded to "$" "$" "$" and so on.10. Use the child shell to generate a separate processThe child shell itself is an independent process. You can use the () operator to define a child shell:Pwd(CD/BIN;LS)PwdWhen executed in a child shell, there is no effect on the current
Qiniu Seven cow problem solutionGetting started with the Shell scripting languageProblem solving Shell Daily learningCd/go to the root directory PWD current directory structure tab blur find complete command IFCONFG view current network information *? [] wildcard character convenient query star flower * match multiple ls *.tar? Matches a single LS m??? [] LS m* [
A goal is a dream with a deadline. Much effort, Much prosperity.Why Encrypt shell scripts? Of course it's for security!Maybe the script involves a password or something, and it needs to be encrypted.I. Download and install the SHC toolTo protect your own shell scripting program, there are many methods, the simplest way there are two: 1, encryption 2, set the expi
line (the current line); P: Print, that is, print out a selected data. Normally p will run with parameter sed-n ~s: Replace, can be directly replaced by work! Usually this s action can be paired with formal notation! For example 1,20s/old/new/g is! EG:NL Regular.txt | Sed ' 2,5d '//delete second to fifth line, the action behind SED must be "extended"NL Regular | Sed ' 2a add hello ' after the second line adds dataNL Regular | Sed ' 2,5c change 2 to 5 line content ' replaces the contents of 2-5
Direcotry" fiOperation Result:$ sh test.sh13File is an ordinary fileNot Direcotrymay also be unfamiliar with some of the above operators, with a detailed list of operators below.
Operator
Description
-B File
Detects if the file is a block device file, and returns True if it is.
-C file
Detects if the file is a character device file, and returns True if it is
-D File
Detects if the file is a directory, and
used to save the script– Use these variables directly– You cannot assign values directly to these variables $# The number of position variables that have been loaded$* values for all positional variables$? Status value after program exit, 0 indicates normal, other value is abnormal$ (): The output of the command, as a parameterCommon Test OptionsCheck file status-e: Document exists as true-D: Document exists and is directory-True-F: Document exists and is file-true-r: Document exists with Read
check if a string begins with the letter "abc"?[[$string = = abc*]][ [$string = = abc*]] and [[$string = = "abc*"]] What's the difference?[[$string = = abc*]]-Check whether the string starts with the letter ABC[[$string = = "abc"]]-check if the string is exactly equal to ABC54) How do I list user names that start with AB or XY?egrep "^ab|^xy"/etc/passwd|cut-d:-f1in bash) $! What does that mean?The PID of the recently executed command in the background.56) $? What does that mean?The end state of
protected]
Same as $*, but quoted when used, and returns each parameter in quotation marks
$-
Displays the current options used by the shell, same as the SET command function
$?
Displays the exit status of the last command. 0 means no error, and any other value indicates an error
Shell Process ControlIf ElseFormat:
If condition
Then
C
True when the length of a string is greater than 0
-Z str1
True when the length of a string is 0
Str
True when the string is non-empty
As an example, compare strings to test the user id:If ["$ (whoami)"! = ' root ']; Thenecho "You had no permission to run $ as Non-root user."Exit 1;Fi
Numeric comparison (integer)
operator
Compare Results
Num1-eq num2
Two numbers equal to True
Getting Started with Shell scripting--NextThis article introduces the following: Logical operators (, | 、!、 ^), test commands, script execution procedures1. Logical operators(1) and short circuit andTrue, False1 0And:1 1 = 11 0 = 00 1 = 00 0 = 0For , if the left condition is false, the value of the right condition is also evaluated. Features as long as a false is assumed to be falseShort Circuit with:
=" wkiom1m89gsqup5laaayxllznls535.png "/> Execution Result: (believe that you know everything)650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/A5/69/wKioL1m89FHR3lnMAAArUD8lCS4739.png "title=" 99. PNG "alt=" Wkiol1m89fhr3lnmaaarud8lcs4739.png "/>Jump out of a single loop Continu statement:Continue [n]: End of the nth layer of the current cycle, and directly into the next round of judgment; the inner layer is the 1th floor.Come on, let's take an example:650) this.width=650; "src=" Http
Gzexe Help Shell Scripting Encryption onFirst, Introductionmany times our script will involve some private information, such as: User name, password, or other important information, we use some encryption to block this information, to ensure that the security of the system has been scripted, usually we only need to bring through the system's own Gzexe This tool is enough.Second, The experimental test b
TopicShell Scripting Knowledge points: What are trap signals in Linux system scripts and how are they used?Reference answer: "Trap signal Command description"The trap command is used to specify the actions to be taken after a signal is received, and a common use of the trap command is to complete the cleanup work when the script is interrupted.Historically, the shell always used numbers to represent the sig
The SED command usage for Shell Scripting Learning notesBasic usage of SEDSed:stream EditorLine EditorSED: Pattern space Stores matched text content in pattern spaceBy default, the original file is not edited, only the data in the pattern space is processed, and then, when the processing is finished, the contents of the schema mode space are displayedSed-N-I: Modify the original file directly-E script-e scr
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.