), in order to better portability, it is recommended to use the second way of writing.
Include a file and execute a file, as well as write the path to the file, not to write the filename, such as the above example:
. ./function.sh
Can not write:
. function.sh
If function.sh is a user-passed parameter, how do you get its absolute path? The method is:
real_path = `readlink -f $ 1` # $ 1 is a parameter entered by the user, such as function.sh
. $ real_p
files under/var/logPut all the commands in one file and build up the script, here is the simplest command to stack up the script, empty the log script.Cd /var/logCat /dev/null > messagesEcho “Logs cleaned up.”Expand: Three ways to empty logs and file contents[[emailprotected] ~]# echo >test.log [[emailprotected] ~]# >test.log [[emailprotected] ~]# cat /dev/null >test.logScenario: Preserve files and empty content.Two Shell language and category Introd
From a programmer's point of view, the shell itself is a program written in C language, from the user's point of view, the shell is the user and the Linux operating system communication Bridge. Users can either enter command execution and use shell scripting to accomplish more complex operations. In the Linux GUI incre
part of a combination statement, such as OK Error | | Other
The end of a series of statements, such as error; Ok
In a judgment statement, including Test, if, while, and so on.These two combinations are used together to save you a lot of time when you debug. For defensive programming, it is necessary to insert them before writing the first line of specific code. Ask yourself, how many times can you write the code at once? Most code, before committing, usually undergoes a process of repeated d
bash_rematch[] array #re1.sh#!/bin/bash# manage to know your nameread-p "Please input your fullname:" Nameif [[$NAME =~ (. *) [[: Space:]] (. *)]];thenecho "Your last name ${bash_rematch[2]}" echo "Your name is ${bash_rematch[1]}" echo "Full name ${bash_rematch[0 ]} "fi execution results [[email protected] shell]#./re1.sh Please input your Fullname:liancao Liu your surname Liu you call liancao full name Liancao Liu71 scripts to guess numbers#一个猜数字的sh
Learn Shell to now, always thought that they will not commit a very two problems, the result of this book last time made a very 2, integrity not protect AH!!! I'm under the test file path except wildcard * and? What can be used outside the same thing, the result of the $home under the implementation of RM. All right, the egg hurts for the whole afternoon! Return the wood to any one of the configuration files. Warn posterity, do not use RM Test wildcar
timeThe encryption function is weak and can only meet the general requirements.There may be a risk that the script will not execute properly after encryptionNoteToday is the 94th Day of the day to accompany you and look forward to your progress .For questions and answers, please leave a comment in the blog comments section .Index of the topic of the previous periodhttp://lidao.blog.51cto.com/3388056/1914205This article is from the "Lee blog" blog, make sure to keep this source http://lidao.blog
1#!/bin/Bash2 ############################################3# @content Chapter8,9of Linux Command line and Shell Scripting Bible4 # @reader Gavin5# @date the/ A/ -6 ############################################7CHAPTER88 9+user varriable make the shell A-computer programTen 1when assigning a value to a user-defined variable, no spaces can appear One 2.
When deploying a task, one of the necessary procedures 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 still in the fear of Python (though I've worked hard in my spare time), so I've written this batch SCP scripting tool using a combination of
Do monitoring and backup up to1. What is a shell script?It's a scripting language, not a programming language.You can use some logical judgments, loops, and other syntaxYou can customize the sub-functionis a collection of system commandsShell scripts enable automated operations, greatly increasing our productivity first shell script: mkdir
quotation marks can parse variables.Three, single quotation marks[[email protected] ~]# var2= ' $var 1 ' [[email protected] ~]# echo $var 2$var1As you can see from the code above, the biggest difference between single quotes and double quotes is that single quotes cannot parse variables, and what is assigned to a variable is not parsed out because it is a variable.Four, anti-quoteAnti-quotes are used primarily to parse commands[Email protected] ~]# whoamiroot[[email protected] ~]# var= ' whoami
, The interpreter (interpreter) needs to read the source code that we wrote and convert it to the target (object), which is then run by the computer. Because each execution of the program is more than the compilation process, so efficiency has decreased.The advantage of using scripting languages is that they are mostly run at a higher level than the compiled language and can easily handle objects such as files and directories, and the disadvantage is
This article collects a bunch of shell scripting tricks, I said, I write a blog mainly to make some learning notes to facilitate their own review, so I will make such an article, there is nothing incomprehensible. About the origin of these techniques, eh, I also forget, may come from Theunixschool, Commandlinefu, cool and igigo.net, of course, there are some of my own experience, tube him, into my brain is
, and the shell interprets the execution.• Batch processing (Batch): The user writes a shell script in advance, with many commands that allow the shell to execute the commands one at a time without having to hit the command one by one.
Shell scripts and programming languages are similar, there are variables and proces
contains the information and location of the source file. Referencing a hard-link file is equivalent to referencing a source fileCp-l test1 test4The-l parameter creates a hard-link test4 that points to the file test1.Note: You can only create hard links between files on the same storage media, and you cannot create hard links between files under different mount points.The parameter-s creates a symbolic link, or a soft connectionCp-s Test TEST5When copying a linked file, be aware that if you use
The while loop is used to continuously execute a series of commands and to read data from the input file; the command is usually a test condition. The format is:While Commanddo Statement (s) to being executed if command is TruedoneThe command finishes, control returns to the top of the loop, and starts from the beginning until the test condition is false.The following is a basic while loop, and the test condition is: Returns True if counter is less than 5. Counter starting from 0, counter plus 1
The Until loop executes a series of commands until the condition is true. The Until loop and the while loop are just the opposite of the processing mode. The general while loop is better than the until loop, but at some point it is only rare that the until loop is more useful.The Until loop format is:Until Commanddo Statement (s) to being executed until command is TruedoneThe command is usually a conditional expression, and if the return value is false, the statement in the loop body continues
First part: Linux command line"Linux command line and Shell Scripting Encyclopedia" chapter I: the first knowledge of Linux shell"Linux command line and Shell Scripting Encyclopedia" chapter II: Into the shell"Linux command line a
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.