In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of Bash variable types, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value, I believe you will gain something after reading this Bash variable type article, let's take a look at it.
Bash variable type local variable local variable environment variable location variable special variable (built-in)
It should be noted here that when assigning a variable, there can be no blank space on both sides of the "=", otherwise an error will be reported.
Root@ubuntu:~# LIST='/etc'root@ubuntu:~# echo $LIST/etcroot@ubuntu:~# LIST='/etc' LIST: command not found local variable
Var_name=value: the scope is available to the entire bash process; variable naming convention:
Can only contain letters, numbers, and underscores, and begin with letters and underscores. It is best not to repeat the name of the environment variable that the system already has. The variable name can fully reflect the role of this variable. Local variable
The declaration of local variables uses the "local" command, and the scope of local variables is valid only in scope. Local var_name=value: scope is the current code snippet
Environment variable
The scope is the current shell process and its child processes, and its parent process cannot be affected. Declare environment variables using the "export" command.
Export var_name=value
If the variable has been defined and you can simply declare the environment variable with the variable name export var_name, you can declare the environment variable in two ways:\ 1. Export var_name=value\ 2. The var_name=value export var_name script starts a sub-shell environment variable when it executes the command: a script that executes automatically by the system (not started on the command line) needs to self-define the required environment variable.
Location variable $1, 2, 3,... Cat first.sh test.txt hello$1: first.sh$2: test.txt$3: hello
Shift: kick out the parameter shift n: kick out n parameters and one parameter by default. Note that the name of the script is called here. If the parameter is used as a variable, the first variable cannot be written directly as 10, but as ${10}.
Special variable
$?: the return value of the last command execution status
Program execution may have two return values:
\ 1. Program execution result
\ 2. If the program status is returned (0-255) 0, if the execution is correct, 1-255 will result in an error (1Magne2127 system reservation); you can customize the return value to get a different error status.
#: get the total number of parameters in the current shell command line
*: get all the parameters of the current shell "2, controlled
@: all parameters of this program "2", which are not controlled by 0, get the file name of the currently executed shell script, get the parameter value of the currently executed script, and get the current process number ()
! The PID that executed the previous instruction
This is the end of the article on "what are the types of Bash variables?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what are the types of Bash variables?" if you want to learn more, you are 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.