In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Bash is used as the standard on Linux, which basically describes the processing and execution of text such as vi editors with ".sh" extensions.
Like programming, it has many functions, such as variables, functions, and arithmetic manipulations, so if you are a Mini Program, you can write it in bash.
In addition, because bash is executed by shell, it is also called a shell script.
Create a shell script
Let's start by creating a simple script that says "Hello World!!" Output to the console.
Use the vi command to create a new file.
$vi hello.sh
After opening the editor, write as follows.
#! / usr/bin/bashecho "Hello wordings!" exit 0
The "#! / usr / bin / bash" on the first line indicates that it is a shell script that uses bash.
The second line describes the statement to be executed.
Finally, exit bash using "exit 0". Parameter 0 indicates a normal end.
After creating the file, use the bash command to execute the shell script.
$bash hello.sh
Execution result:
Hello World!!
Hello World!! Output
In addition, in addition to bash, commands for executing shell scripts are also run with ". /" to change the execution permissions.
$chmod 755 hello.sh$. / hello.sh
There is a way to execute with the sh command.
$sh hello.sh
Shell scripts can be written for comments and programming.
Comments can be written after "#".
#! / usr/bin/bashecho "Hello wordings!" # ends processing. Exit 0
Shell scripts can define variables and assignments.
#! / usr/bin/bash num=100PI=3.14STR1= "Hello" str_2= "Worldlings!" Echo ${num} echo ${PI} echo ${STR1} echo ${str_2} exit 0
Variables can be alphanumeric characters, such as uppercase and lowercase letters, numbers and underscores (_).
When assigning a value to a variable, write it as variable = value.
Note that placing spaces before and after the "=" will result in an error.
In addition, when accessing variables, you need to add "$" before the variable name, such as "${variable}", to enclose the variable in "{}".
Input and output
#! / usr/bin/bash read AGEecho "ege=$AGE" exit 0
Execution result:
30ege=30
Read stores input from the console to the variable specified in the parameter.
The variable specified by read can be called a normal variable.
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.