, 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
Shell Getting Started Tutorial (1)-shell-JUSTKK's Column-Blog channel-csdn.nethttp://blog.csdn.net/justkk/article/details/43795131
Shell Getting Started Tutorial (2)-Variables and Parameters-JUSTKK-Blog channel-csdn.nethttp://blog.csdn.net/justkk/article/details/44081993
script rotatefile can solve this problem. This script can rename the message to save the file (assuming outmail) is OUTMAIL.1, and for outmail.1 it becomes outmail.2 and so on ...
The code is as follows:
#!/bin/sh
# vim: set sw=4 ts=4 et:
ver="0.1"
help()
{
cat
How does this script work? After detecting a file name provided by the user, we perform a 9 to 1 loop. File 9 is named 10, file 8 is renamed to 9, and so on. After the loop is complete, we name the original file 1
# input Check:If [-Z ']; ThenError "Error:you must specify a file, use-h for help"FiFilen= "$"# Rename any. 1,. 2 etc File:For N in 9 8 7 6 5 4 3 2 1; DoIf [-F ' $filen. $n "]; Thenp= ' expr $n + 1 'echo "MV $filen. $n $filen. $p"MV $filen. $n $filen. $pFiDone# Rename the original file:If [-F "$filen"]; Thenecho "MV $filen $filen. 1"MV $filen $filen. 1Fiecho Touch $filenTouch $filenHow does this script work? After detecting a file name provided by the user, we perform a 9 to 1 loop. File 9 is na
But not on Mac OS,/bin/sh and/bin/bash are two different files, although their size is only about 100 bytes apart:
iMac:~ wuxiao$ ls -l /bin/*sh
-r-xr-xr-x 1 root wheel 1371648 6 Nov 16:52 /bin/bash
-rwxr-xr-x 2 root wheel 772992 6 Nov 16:52 /bin/csh
-r-xr-xr-x 1 root wheel 2180736 6 Nov 16:52 /bin/ksh
-r-xr-xr-x 1 root wheel 1371712 6 Nov 16:52 /bin/sh
-rwxr-xr-x 2 root wheel 772992 6 Nov 16:52 /bin/tcsh
-rwxr-xr-x 1 root wheel 1103984 6 Nov 16:52 /bi
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
functionality is written in C or C + +, it can take two days, and generally, the script executes fast enough to allow people to ignore its performance problems. Examples of scripting languages are awk, Perl, Python, Ruby, and Shell.
When to use the shell
Because the shell
complex code that makes it difficult for developers to read and modify them.
Usually, its syntax and interpretation are not so flexible, and not intuitive.
Its code is usually not used by other scripts. The code reuse rate in the script is very low, and the script usually solves some very specific problems.
They generally do not support library features, such as HTML interpreters or processing HTTP request libraries, because libraries are generally only in the popular language and
code.
8. Avoid weaknesses
Sometimes, using a shell to write a script means that it is difficult to migrate, make it difficult to handle errors uniformly, and handle data easily.Although the use of external commands can quickly and easily achieve a variety of complex functions, but as the reverse side of the coin, you have to rely on grep, SED, awk and other tools to glue them together.
If you have multiple platform-compatible requirements, be care
-rwxr-xr-x 1 root wheel 1103984 6 Nov 16:52 /bin/zsh
Advanced programming languages
In theory, as long as a language provides an interpreter (not just a compiler), the language is capable of scripting, and common explanatory languages can be used for scripting, such as Perl, TCL, Python, PHP, and Ruby. Perl is the oldest
bo friends Good, due to the continuous development of operation and maintenance related technology, personal ability has been improving, gradually accumulated experience can not be updated to the previous blog post. Therefore, in order to better help you learn the operation and maintenance technology, specifically for the shell and Python scripting language summa
Bo friends, due to the continuous development of operation and maintenance related technology, personal ability is constantly improving, the daily accumulation of experience can not be updated to the previous blog post. Therefore, in order to better help you learn the operation and maintenance technology, specifically for the shell and Python scripting language s
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
read command to assign values to variables, the read command prompts the user to enter user information for a simple interactive process # # #
Read [-P ' hint message '] variable name
[email protected]/]# Read ToDir2
/opt
[Email protected]/]# echo $ToDir 2
/opt
·
####################Setting the scope of the variable ####################
[Email protected]/]# echo "$Product $Version"
Python 2.7.13
[Email protected]/]# export Product Version # # # #Set
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
Learn the first script from the shell, thanks to cloud Li Qiangqiang Teacher's shell programming tutorial
To create a shell script file:Touch menu.shTouch index.shTouch welcome.sh
To give the script file permission to execute:chmod a+x menu.sh index.sh welcome.sh
menu.sh
#!/bin/bash#menu.shfunctio
Learn the first script from the shell, thanks to cloud Li Qiangqiang Teacher's shell programming tutorial
To create a shell script file:Touch menu.shTouch index.shTouch welcome.sh
To give the script file permission to execute:chmod a+x menu.sh index.sh welcome.sh
menu.sh
#!/bin/bash#menu.shfunctio
Bo friends, due to the continuous development of operation and maintenance related technology, personal ability is constantly improving, the daily accumulation of experience can not be updated to the previous blog post. Therefore, in order to better help you learn the operation and maintenance technology, specifically for the shell and Python scripting language s
what's the feature of this bash?1) Record command historyThe commands we've knocked on, Linux will be recorded, and presets can record 1000 historical commands. These commands are saved in the. bash_history file in the user's home directory. One thing you need to know is that commands that run in the current shell are saved to the. bash_history file only when the user exits the current shell normally.There
scripts written in Other languages include shell scripts written by PHP:Sometimes we may need to include shell scripts written by PHP in shell scripts written in other languages. Actually very simple, here is a simple example:#!/bin/bashEcho this was the Bash section of the code./usr/local/bin/php-q print ("This was the PHP section of the code\n");?>EOFIn fact,
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.