Learn about linux shell scripting cookbook pdf, we have the largest and most updated linux shell scripting cookbook pdf information on alibabacloud.com
The Linux Shell Script Foundation has been divided into several parts, where the content of the control process is immediately finished, this is the last part about here document, where the example is a little bit more complex, we slowly analyze this complex Linux shell script.
6. Here documents
When you want to pass a
Previous section Review In the previous blog post, I focused on the background of Shell scripting, how to create the first shell script in life, and the shell variables. The next step is to introduce shell programming, mainly around she
addition to Shebang, the # occupies the absolute beginning of the content, is the comment line, the interpreter ignores the contents of such a line;3. The explanation ignores all blank lines in the script;4. Lots of commands and keywords (if,else,then,do,while,for, ... )Note: Once the shell script runs in the current shell according to Shebang's instructions, an interpreter (child
"
Else
echo "$val ^ 2
Fi
Str1=xcyhaha
if [[$str 1 = = xcy*]]
Then
echo "str1 = = xcy*, str1 is $str 1"
Else
echo "STR1! = xcy*, str1 is $str 1"
Fi
12.7 Case CommandWith the case command, you don't have to write all the elif statements to keep checking the value of the same variable.The case command takes a list format to examine multiple values for a single variable.Syntax: Note the two semicolons that followCase variable inPattern1 | PATTERN2)
Because some registered user account rules can follow, and usually people's awareness of the poor, the password is relatively simple, the user name of the common password login test, to break the password.For learning purposes only, do not use for illegal use. The code has been partially modified, does not work properly, the test needs to modify the code according to the actual needs, in addition to the password security issues must be enough attention.Design ideas:
Intercept HTTP packets
]:~/learn$ cat Args.txt | Xargs SH cecho.sh;Arg1 arg2 arg3#Requirement 3, how do I embed parameters in a fixed command line? As shown below:Copy CodeThe code is as follows:[Email protected]:~/learn$ sh cecho.sh-p args1-1-P args1-1#[Email protected]:~/learn$ sh cecho.sh-p args2-1-P args2-1#[Email protected]sli-pc:~/learn$ sh cecho.sh-p args3-1-P args3-1#Solutions for using Xargs:Copy CodeThe code is as follows:[Email protected]:~/learn$ cat Args.txt | xargs-i {} sh cecho.sh-p {}-1-P arg1-1#-P arg
updated successfully.Changing password for user bruce03.Passwd:all authentication tokens updated successfully.Changing password for user bruce04.Passwd:all authentication tokens updated successfully.Changing password for user bruce05.Passwd:all authentication tokens updated successfully.Changing password for user bruce06.Passwd:all authentication tokens updated successfully.Changing password for user bruce07.Passwd:all authentication tokens updated successfully.Changing password for user bruce0
Linux shell Script Basic Learning this part if only look at the theoretical part of the previous, although there are some examples, but not enough system, here will be a concrete example to show you the Linux shell script programming to help you improve the Linux
BKJIA Translation: It feels great when you understand Shell scripts and can write them smoothly whenever needed. In this chapter, we will teach you how to use scripting to perform complex mathematical operations.
Let's start with the Fibonacci series.
The Fibonacci series, also known as the Golden split series, refers to a series of 0, 1, 1, 2, 3, 5, 8, 13, 21 ......, Each of its items is the sum of the fir
can download the code for this example from here. Example Two: colorful Scripts Linux terminals also support colorful, please see the following script: #!/bin/bashClearEcho-e " #092; #048; 33[1m Hello World"# Bold EffectEcho-e " #092; #048; 33[5m Blink"# Blink effectEcho-e " #092; #048; 33[0m Hello World"# Back to NoramlEcho-e " #092; #048; 33[31m Hello World"# Red ColorEcho-e " #092; #048; 33[32m Hello World"# Green ColorEcho-e " #092; #048; 33[33m
Find a very detailed Linux shell script tutorial, in fact, not only the shell script programming, but also introduced the system of various commandsHttp://vdisk.weibo.com/s/yVBlEojGMQMpvThis book is divided into five parts, in detail the shell programming skills, a variety of UNIX commands and syntax, but also related
No orders found.
128
Invalid exit parameter
128+x
Critical error for Linux signal x
130
Command terminated with CTRL + C
255
Exit status code out of bounds
Exit Exit command can specify exit status code, but not more than 255, otherwise it will be moduloCode 1-16[Email protected]:/data# cat Demo4 #!/bin/bashdateecho $?whoexit 5[email protected]:/data#./dem
-be-sustained by perpetual neglect of many and other things. Robert Louis Stevenson (1850-1894)
[Email protected]:~/shell/26zhang$
Note this:#grep "$ (date +%b '%-d, '%Y)"-A2 |Since my Ubuntu is in Chinese, I have not been searching for November. I'm going to replace it with this one, only 28, 2017.grep ", $ (date +%y)"-a2 | # Xcy AddIt would have been like this grep "$ (date +%-d, '%Y)"-A2 | # xcy Add, don't know why my date is 29. And the site is
/etc/crontab Add the following code: Here's an example of an hourly 26-minute execution: * * * * * root/home/**/wewang/autobackupmysql_qas.sh If executed at three O ' Day, then: XX 3 * * * root/home/**/wewang/autobackupmysql_qas.sh Case 2:redhat situation. ( that is, the currently used Linux system ) Copy the script you just edited to the appropriate directory
[Email protected]***** wewang]# CP autobackupmysql_qas.sh/etc/cron.da
file is a script that is executed when the Linux system startsEdit the Inittab file (use the Vim/etc/inittab command to open the file)Example: Add a statement to the Inittab file to allow the system to execute a shell script file that checks the system disk when it starts checkdisk.shcheckdisk::once:/sbin/checkdisk.sh >/dev/console 2>1 indicates that this command is executed at each runlevel, if it is to b
, which is represented as a local variable. such as local temp=1 .Example 3. Array Parameterstest3.sh#!/bin/bash Span class= "hljs-comment" ># trying to pass a array variable function testit {local newarray # use ' local ' define a local variable newarray= (' echo " the NewArray value is ${newarray[*]} "}myarray= (1 , 2 , 3 , 4 , 5 ) echo "the original array is:${ Myarray[*]} " testit $myarray Test:sh test3.shOutput:The original array is:1,2,3,4,5The NewArray value is 1,2,3,4,5Example
fileYou can also connect many parameters.such as Sort-t ': '-K 3 testYou can think of it as something inside. xxx1:xxx2:xxx3:xxx4:xxx5means to sort the xxx3-T: Specifies a character to distinguish the key position-K:--key=pos1[pos1]. The sort starts with pos1, and if POS2 is specified, it ends at Pos2.| Redirects the output of the du command to the sort command.-r: Indicates descending order.Here is an example:4.3.21. grep [options] pattern [file]For example:grep t test//Search for text in test
instruction (displays the exit status of the last command. 0 means no error, any other value indicates an error)$-shows the current options used by the shell, same as the SET command function[email protected] is similar to $*, but can be used as an array--------------------------------------------------------------------------------------------------#!/bin/sh##############Export lang= "ZH_CN. GB18030 "Export JAVA_HOME=/USR/LOCAL/JDKExport path= $JAVA
Previous Edit CommandA: Append data after the current cursorO: The next line of the cursor inserts dataDW Delete a Wordd$ Delete to end of lineDD: Delete Row, 5dd delete 5 rowsThe use of backspace and delete keys in normal mode is not recognized.10.1.4 Copy and pasteDD can be pasted with p after deletion.The copy command is Y,YW copy a wordy$ Copy to end of lineThen use p to paste10.1.5 Find Replacement: s/old/new/g a line command to replace all old, which is replaced only on one line: N,ms/old
value of a running process Renice-n PIDNohup SH executes scripts in the backgroundCtrl Z hangs a foreground processFG Job Number The file foreground runs the BG job number to run the file background/proc DirectoryShell Scripts Scripta shell script is a text file that contains a shell directiveShell and oh ah this supports variables with simple syntax to complete batch workHow
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.