In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what the Linux script Shell commands are, and the editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
1. The beginning
The program must start with the following line (only on the * * line of the file):
#! / bin/sh
Symbol #! It is used to tell the system that the parameters behind it are the program used to execute the file. In this example, we use / bin/sh to execute the program.
When you edit a script, you must also make it executable if you want to execute it.
To make the script executable:
Compile chmod + x filename so that you can run it with. / filename
two。 Annotation
In shell programming, sentences that begin with # indicate comments until the end of the line. We sincerely recommend that you use comments in your program. If you use comments, you can understand how the script works and how it works in a short period of time, even if you haven't used the script for a long time.
3. Variable
You must use variables in other programming languages. In linux script shell programming, all variables are made up of strings, and you don't need to declare variables. To assign a value to a variable, you can write:
#! / bin/sh
# assign values to variables:
A = "hello world"
# now print the contents of the variable a:
Echo "An is:"
Echo $a
Sometimes variable names are easily confused with other words, such as:
Num=2
Echo "this is the $numnd"
This does not print out "this is the 2nd", but only "this is the", because shell searches for the value of the variable numnd, but this variable has no value. You can use curly braces to tell shell that we are printing the num variable:
Num=2
Echo "this is the ${num} nd"
This will print: this is the 2nd
4 Environmental variables
Variables that have been processed by the export keyword are called environment variables. We don't discuss environment variables because they are usually only used in login scripts.
5 linux script Shell command and flow control
You can use commands in shell scripts:
Unix command:
Although arbitrary unix commands can be used in shell scripts, there are still some relatively more commonly used commands. These commands are usually used for file and text manipulation. Common command syntax and functions
◆ echo "some text": print text on the screen
◆ ls: file list
◆ wc-l filewc-w filewc-c file: calculate the number of lines in the file, calculate the number of words in the file, calculate the number of characters in the file.
◆ cp sourcefile destfile: file copy
◆ mv oldname newname: renaming or moving files
◆ rm file: deleting files
◆ grep 'pattern' file: search for strings such as grep' searchstring' file.txt within a file
◆ cut-b colnum file: specify the range of file contents to be displayed and output them to a standard output device such as: output the 5th to 9th characters per line cut-b5-9 file.txt should never be confused with the cat command. These are two completely different commands.
◆ cat file.txt: output the file contents to a standard output device (screen)
◆ somefile: get the file type
◆ read var: prompts the user for input and assigns input to variables
◆ sort file.txt: sorts lines in the file.txt file
◆ uniq: delete the rows that appear in the text file, such as: sort file.txt | uniq
◆ expr: doing mathematical operations Example: add 2 and 3expr 2 "+" 3
◆ find: search for files such as find by file name. -name filename-print
◆ tee: output data to standard output devices (screens) and files such as: somecommand | tee outfile
◆ basename file: returns a file name that does not contain a path, for example: basename / bin/tux will return tux
◆ dirname file: return the path where the file resides, for example: dirname / bin/tux will return / bin
◆ head file: print the first few lines of a text file
◆ tail file: print the last few lines of a text file
◆ sed: Sed is a basic find and replace program.
You can read text from standard input, such as command pipes, and output the results to standard output (screen). This command uses a regular expression (see reference) to search. Don't be confused with wildcards in shell. For example, replace linuxfocus with LinuxFocus: cat text.file | sed's awk is used to extract fields from a text file. By default, the field delimiter is a space, and you can use-F to specify another separator. Cat file.txt | awk-F,'{print $1 ",'$3}'we use here as a field separator to print * and the third field at the same time. If the contents of the file are as follows: Adam Bor, 34, IndiaKerry Miller, 22, USA command output is: Adam Bor, IndiaKerry Miller, USA.
This is the end of this article on "what are the Linux script Shell commands?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.