In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "what does the shell script in linux refer to?", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what the shell script in linux refers to" article.
In linux, shell scripts are a way of programming, which is a collection of commands. Shell script will write some shell syntax and instructions inside, using pipeline commands and traffic redirection and other functions to achieve the desired processing purpose, is temporarily written Mini Program to complete the current work.
The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
What is a shell script in linux
I. the concept and significance of shell script
Shell script is a programming method under linux, script (shell script) is a program written by the function of shell, this procedure is to use plain text files, write some shell syntax and instructions in it, and then use normal representation, pipeline commands and data flow redirection and other functions to achieve the processing purpose we want. To put it bluntly, it is to solve the practical problems of linux, temporarily write a Mini Program to complete the current work, if you need to use it many times, it can also be saved and recycled.
two。 The specification of the script
The script uses the shebang mechanism, that is, the format:! # / bin/bash 、! # / use/bin/python . You need to simply interpret the shell script. Here is an example:
#! / bin/bash#-# Filename: hello.sh# Revision: 1.The Date: 2017Unip 08 Universe Author: Mr.Dong# Email: Dong@gmail.com# Website: www.magedu.com# Description: This is the first script#-echo "hello world"
With this information, you can quickly know the usefulness of this script for your work.
You can use the following two commands to debug scripts at run time
Bash-n hello.sh to check the syntax errors of the script
Bash-x hello.sh can view the execution steps of the script
three。 Variable
1. Local variable
The local variable is valid only for the current shell and not for the child shell (how many levels of shell is the SHLVL view).
Variable assignment: name='value'
String assignment: name= "root"
Variable reference: name= "$USER"
Command reference: name=COMMAND name=$ (COMMAND)
Show all defined variables: set
Delete variable: unset name
two。 Environment variable
The environment variable is valid for the current SHELL and its child SHELL.
Declaration and assignment commands for variables:
Export name=VALUEdeclare-x name=VALUE
Reference to the variable: $name,$ {name}
Show all environment variable commands:
Env printenv export declare-x
Bash comes with environment variables:
PATH SHELL USER UID HOME PWD SHLVL LANG MAIL HOSTNAME HISTSIZE
3. Read-only variable
Declare a read-only variable:
Readonly namedeclare-r name
View the read-only variable: readonly-p
4. Location variable
$1, $2,... Corresponding to the first and second parameters, shift [n] changes position.
$0: command itself
$: all parameters passed to the script, all of which are combined into one string
$@: all parameters passed to the script, each of which is a separate string
$#: the number of parameters passed to the script
$@ $makes a difference only when it is enclosed in double quotation marks
Set-
four。 Arithmetic operation and logic operation
1. Arithmetic operation
Arithmetic operator: +-* /% (remainder) * * (multiplier)
Common operations:
(1) let var= arithmetic expression
(2) var=$ [arithmetic expression]
(3) var=$ ((arithmetic expression))
(4) var=$ (expr arg1 arg2 arg3 …)
(5) declare-I var = value
(6) echo 'arithmetic expression' | bc
Generate random number command: random number between echo $[$RANDOM%number] 0-number
Assignment operation: + =-= * /% =
Increase and decrease:
Let var+=1let var++let var-=1let var-
two。 Logical operation
True=0 false=1
It is the same as 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.
Or 1 | | 1: 1 / 1 | | 0: 1 0 | | 1: 1 0 | | 0: 0
No! 1-0! 0-1
Five. Test command
The test command is a utility for testing conditional expressions in the shell environment.
For example:
Test "$A" = = "$B" & & echo "Strings are equal" ["$A" = = "$B"] & & echo "Strings are equal"
The two expressions express the same meaning.
[[]] indicates support for regular expressions
Numeric comparison: string comparison:
-whether the gt is greater than >
Whether ge is greater than or equal to > =
Is-eq equal to = =
Whether ne is not equal to! =
-whether the lt is less than
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.