Alibabacloud.com offers a wide variety of articles about linux shell scripting tutorial for beginners, easily find your linux shell scripting tutorial for beginners information here online.
1. Linux Scripting Basics1.1 Basic Introduction to grammar1.1.1 StartThe program must start with the following line (must be placed on the first line of the file):#!/bin/shThe symbolic #! is used to tell the system that the parameters behind it are the programs used to execute the file. In this example we use/BIN/SH to execute the program.When you edit a good script, you must also make it executable if you
Basics of Linux Shell scripting here we first talk about the shell of the basic syntax, the beginning, comments, variables and environment variables, to do a basic introduction, although not related to specific things, but lay the foundation is to learn easily after the premise.
1.
command. You can use Echo to print any variable value in any place where you suspect it is wrong. That's why most shell programmers spend 80% of their time debugging programs. of the Shell programThe advantage is that there is no need to recompile, and it does not take much time to insert an echo command.The shell also has a real debug mode. If there is an error
2017 09:48:22 +0800from localhost [127.0.0.1]-----The following addresses had permanent fatal errors-----[email protected]>(reason:550 Failed to connect remote host.)-----Transcript of Session follows-----... while talking to mx3.qq.com.:... while talking to mx2.qq.com.:So the machine was restarted a bit. You can do it.[Email protected]:/var/mail$ Echo]20171204tete" | Mail-s "TEst2"Xcy[Email protected]:/var/mail$ Mail"/var/mail/xcy": 3 messages 1 new 2 unreadU 1 Mail Delivery Subs December 4 10
be output to the monitor while redirecting files, but generally overwrite the original file content, you can use the-a append contentCode 5-23[Email protected]:/data# date | Tee Textmon Dec 5 06:18:04 CST 2016[email protected]:/data# cat text Mon Dec 5 06:18:04 CST 2016[email protected]: /data# who | Tee text root pts/0 2016-12-05 04:26 (122.90.143.21) [email protected]:/data# cat text root pts/0 2016-12-05 04:26 (122.90.143.21) [Email protected]:/data# date | Tee-a text
[Turn]http://www.knktc.com/2011/08/20/linux-shell-expect%e6%89%b9%e9%87%8fscp%e8%84%9a%e6%9c%ac%e5%b7%a5%e5%85%b7/
One of the most recent tasks in preparing a deployment is to send some files, such as installation packages, to a large number of servers. Although there is already a Brother Woo script available: A Python script written by the SSH and SCP features provided by the Paramiko module. But I'm stil
used with variable names, and if the loop body does not include a variable name, a dead loop may occurHow the list is generated:1) Give a direct2) List of pure integersSEQ: Output An integer listseq [First [INCREMENT]] Last3) curly braces unfold{first.. Last}4) return value of the execution result of the command5) GLOBBING6) references to certain variables: [email protected], $*Features of the For loop:1. There is almost no cycle of death;2. The entire list needs to be loaded into memory during
results of "mail.jpg tux.jpg".quotation marks (single and double quotation marks) prevent this wildcard extension:
#!/bin/shecho "*.jpg" Echo ' *.jpg '
This will print "*.jpg" two times.Single quotes are more restrictive. It prevents any variable expansion. Double quotes prevent wildcard expansion but allow variable expansion.
#!/bin/shecho $SHELLecho "$SHELL" Echo ' $SHELL '
The result of the operation is
.2) read uses the IFS character to parse the text, and here we specify the IFS as a comma.Cat >> $outfile This includes an output append redirect (>>) and an input append redirect (>> appends the output of the cat command to the file specified by the $outfile variable.The input to the Cat command is not taken from standard input, but is redirected to the data stored in the script.The EOF symbol marks the beginning and end of the data appended to the file.Input file + run + Result:DescriptionSpe
specified shell command
V
Start the VI editor with the current file
.
Repeat the previous command
N
Find in file the overflow matches the content of the specified expression
‘
Jumps to the first content that the specified expression matches to
Ctrl+l
Redraw the current scre
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
Bit left shift
>>
Bit right Shift
Bit Boolean and
|
Bit Boolean or
Logic and
||
Logical OR
Code 2-11[Email protected]:/data# cat Demo3 #!/bin/bashval1=10if (($val 1 * * 2 >) then ((val2= $val 1 * * 2)] echo "The sq Uare of $val 1 is $val 2 "Fi[email protected]:/data#./demo3 the square of 100 use both brackets[[Expression]] provides another feature
file Content:bin:x:2:2:bin:/bin:/usr/sbin/nologin The done command is useful for looping the results of a loop to another command, redirecting to a file or screen, and using other commands to display to the screen[Email protected]:/data# cat Demo7 #!/bin/bashfor State in ' North Dakota ' Connecticut Illnois Alabama Tennesseedo Echo "$state is the next place to go" done | Sort > Textecho "This completes we travels" [email protected]:/data#./demo7 This completes our travels[email protecte
Linux shell scripting:1. Program Structure Exercise: Write a script, given a positive integer, to calculate the sum of all digits of this number.For example, if the program is given input 123, it should return 1+2+3=6.2. Program Structure Exercise: Write a script, given a positive integer, to output this number in reverse order.For example: program input 123, the
1. After opening the terminal prompt, $ represents a normal user, #表示管理员用户root, root is the most privileged user in the Linux system.2. A shell script is usually a text file with a #! start, where #! precedes the interpreter path. Example: #!/bin/bash3. Note section starts with #, and consistently continues to the end of the line4. By default, Echo adds a line break after each call. The text after echo can
The remaining space is Morethan the%, the message is sent to the Wl#tue2 the: $: AboutCst .PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wl/Binexport PATH forRemainingspaceinch$(DF-H |awk '{print $}'|grep-V' Use'|sed-E's/[%]//g') Do if[[$RemainingSpace > the]]; Then Echo-E"$RemainingSpace" Echo-E"$ (df-h | grep $RemainingSpace)">/service/script/. Harddiskwarning Mail-S"Disk Warning"WL . Harddiskwarningfi Done4. Detecting remaining Inode#!/bin/Bash#inspcet Inode
script requires a user name list file as a parameter2) If no parameters are provided, this script should give a hintUsage:/root/batchusers, exit and return the corresponding value3) If a nonexistent file is provided, this script should give aShow Input file not found, exit and return the corresponding value4) New User login Shell is/bin/false, no need to set password5) User list test file:Http://classroom/pub/materials/userlist# wgethttp://classroom/
Overview:Overview:This section describes the array of shell scripting in Linux, advanced string processing, advanced variables, and configuring the user's environment.One, function and positional parameter extension1. TheShift command implements the jump in the position parameter, which squeezes the leftmost parameter650) this.width=650; "src=" Http://s1.51cto.co
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.