In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Cloud Computing Learning Route course outline Courseware, Linux beginner tutorial explanation:
V > basic knowledge of Shell programming
The basic syntax structure of No.1 Shell script
The first line: "#! / usr/bin/env bash" is called shebang, and the shell syntax specifies that the shell script file first acts as the interpreter of the whole file.
The second line: the behavior comment line that starts with "#" will not be read by the program by default, and can be used to explain the document and calibrate the owner, or to explain the program.
Line 7: to format the print statement printf, printf can print the following "hello world" to the specified terminal,\ nA newline character
No.2 local and global variables and environment variables
All programming languages use variables to store data for later use or modification. What is different from compiled languages is that most scripting languages do not need to advance
Declare the type of variable, which is what type is used, and when we want to reference the variable, we can access it by preceded by a $symbol.
The value of this variable. The variables normally set by shell are global variables, even inside the function body.
Like other programming languages, the copy form of a variable is the value set by the variable name =
[root@bavdu ~] # vim helloworld.sh
-.sh means that the file is a shell script with an extension suffix. If you omit .sh, it is not easy to judge the text.
Whether the item is a shell script
#! / usr/bin/env bash-shebang snake stick, interpreter, translation
#
Author: bavduEmail: bavduer@163.comGithub: https://github.com/bavdu-this is the comment. You read Date: 2019//printf "hello world\ n" correctly.
[root@bavdu ~] # sh helloworld.sh
Hello world
[root@bavdu ~] #. / helloworld.sh
[root@bavdu ~] # vim variable_daemon01.sh
#! / usr/bin/env bash
#
Author: bavduEmail: bavduer@163.comGithub: https://github.com/bavduDate: 2019//
Fruit=apple # assigns "apple" to the variable fruit
Count=10
Printf "We have $count ${fruit} (s)\ n"
Count=20 compared with global variables, there are local variables, the definition of local variables need to be declared by local.
Shell also has built-in variables to store frequently used configuration information, such as available printers, search paths, etc., which are called environment variables on the terminal.
You can see the built-in environment variables in the system by typing the env command. The environment variables are usually set to / etc/profifile or / etc/profifile.d/*..
Printf "we have $count apples"
Printf "we have $count apples"
Printf "we have $count apples"
Printf "we have $count apples"
Printf "we have $count apples"
Printf "we have $count apples"
Printf "we have $count apples"
[root@bavdu ~] # sh variable_daemon01.sh
[root@bavdu ~] # vim variable_daemon02.sh
#! / usr/bin/env bash
#
Author: bavduEmail: bavduer@163.comGithub: https://github.com/bavduDate: 2019//
Hello () {
Local VARIABLE= "hello world"
Printf "$VARIABLE\ n"
}
Hello
Printf "$VARIABLE\ n"
[root@bavdu shell_s] # vim / etc/profile
Export BAVDU= "Hello Bavdu."
[root@bavdu shell_s] # source / etc/profile
[root@bavdu shell_s] # vim variable_daemon03.sh
#! / usr/bin/env bash
#
Author: bavduEmail: bavduer@163.comGithub: https://github.com/bavduDate: 2019//
Printf "$BAVDU\ n"
[root@bavdu shell_s] # sh variable_daemon03.sh
Hello Bavdu.
[root@bavdu shell_s] #
[Example]
[root@shell Downloads] # wget https://download.oracle.com/otn-shell also has some special variables called location variables, which allow us to add corresponding parameters when we execute. Let's take a look at:
In the script, we also often read the variables entered by the user, so there is also a read keyword, which is specifically used to read the numeric value or string entered by the user, thus assigning
Value to a variable.
Pub/java/jdk/12+33/312335d836a34c7c8bba9d963e26dc23/jdk-12_linux-x64_ bin.tar.gz ^ C
[root@shell Downloads] # ls
Jdk-12_linux-x64_bin.tar.gz program
[root@shell Downloads] # tar xf jdk-12_linux-x64_bin.tar.gz-C / usr/local/
[root@shell Downloads] # cd / usr/local/
[root@shell local] # ls
Bin etc games include jdk-12 lib lib64 libexec sbin share src
[root@shell local] # mv jdk-12 java-12
[root@shell local] #
[root@shell local] # java-version
Openjdk version "1.8.0,181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
[root@shell local] #
[root@shell local] # vim / etc/profile
#-java env-#
Export JAVA_HOME=/usr/local/java-12
Export PATH=$JAVA_HOME/bin:$PATH
Export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#-java env-#
[root@shell local] # source / etc/profile
[root@shell local] #
[root@shell local] # java-version
Java version "12" 2019-03-19
Java (TM) SE Runtime Environment (build 12: 33)
Java HotSpot (TM) 64-Bit Server VM (build 12: 33, mixed mode, sharing)
[root@bavdu shell_s] # vim variable_daemon04.sh
#! / usr/bin/env bash
#
Author: bavduEmail: bavduer@163.comGithub: https://github.com/bavduDate: 2019//
Printf "$1 $2 $3\ n"
[root@bavdu shell_s] # sh variable_daemon04.sh bavdu is goodboy
Bavdu is goodboy [root@bavdu shell_s] # vim variable_daemon05.sh
#! / usr/bin/env bash
#
Author: bavduEmail: bavduer@163.comGithub: https://github.com/bavduDate: 2019//
Read-p "Please input your variable:" varName
Printf "$varName\ n"
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.