In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what the Linux shell script is, which is very detailed and has a certain reference value. Friends who are interested must finish it!
Linux shell script sharing
Shell is a command interpreter between the kernel and the user, responsible for passing the user's instructions to the kernel and echoing the execution results to the user. Shell is a program written in C language, it is a bridge for users to use Linux, at the same time, Shell can also be used as a powerful programming language.
What we often say Shell means command line interpreter and a shell on the kernel. Several common types of Shell include script support provided by sh, csh, bash, zsh and so on.
Shell was born in Unix and is a script programming that interacts with Unix/Linux. It is meaningless to learn Shell alone. Students with Linux foundation should know that Linux integrates Shell environment by default, and the function point of Shell lies in the use of external commands.
In the aspect of internal data processing, it focuses on text (or string, or character stream) processing, while the native processing of operations and other basic data structures (such as array, set, map, etc.) is weak, and the function goal is to realize command automation.
However, while realizing command automation, Shell needs to rely on other programs to complete most of its work, which is its defect and an advantage, but its indisputable advantage is its concise scripting language markup, and it executes faster and more efficiently than programs written in C language.
So if we have friends who do operation and maintenance or even basic management of Linux servers, as long as we learn Shell programming, we can greatly save our time and manage our servers more quickly.
Bash is the default Shell of the Linux standard and an acronym for BourneAgain Shell, because bash has many features, such as: you can use functions similar to doskey under DOS, use the arrow keys to look up and quickly enter and modify commands. Automatically give a command that begins with a string by looking for a match
In addition, bash contains its own help function. You only need to type help at the prompt to get relevant help. In Linux systems, we often see the contents of a file that begins with: #! / bin/bash, which declares that the file is a Shell programming file based on bash.
Practical information
There is a program like this:
#! / bin/bashcd / home/liwei/mongodb/bin./mongod-- dbpath=../liwei_db
We know that calculations are executed one by one when executing instructions. Then it is easy to understand the above three lines. The purpose of the sequential operation is to enter the mongodb/bin directory, then execute the startup mongodb data and save it as m.sh, so that as long as we execute a line in the Linux terminal: sh m.sh, enter, the calculation will execute the instructions in turn to achieve the function of starting the mongodb database.
So we need to execute more instructions, okay? The answer is yes, if we need to execute hundreds of lines of instructions and execute them separately, we have to repeat the operations, then write them into a Shell in turn, so that it is very convenient to execute them. During the execution of Shell, we can record the result reports of some nodes by > or > >.
For example, a shell:
#! / bin/bashcd / lampls * .tar.gz > ls.listfor TAR in `cat ls.list`dotar-zxf $TARdone
The practical problem to be solved by this Shell is to extract all the compressed packages in the lamp directory in batches, so that we can see that the result set of ls can be used to participate in the execution of the next instruction.
So now we have a need to change all the uppercase letters in the names of files under a certain folder to lowercase letters, if we have to change them one by one manually, but it is painful to find files. At this time, Shell has played a powerful role.
#! / bin/bashfor file in `ls | grep'[Amurz] '`dostr= `echo $file | tr' Amurz''amurz' `mv $file $str
In this way, a complex operation is well solved.
Sometimes when we manage files, we need to delete all empty files and useless files.
For filename in `ls`doif test-d $filenamethen b=0else aura $(ls-l $filename | awk'{print $5}') if test $a-eq 0 then rm $filename fifi done is all about what the Linux shell script is, thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.