In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the bash variable types of Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
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 is already defined, you can simply declare the environment variable with the variable name export var_name 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 executed automatically by the system (not started on the command line) needs to define the required environment variables by itself.
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: there may be two return values for program execution:
\ 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 content of "what are the bash variable types of Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.