In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to name the variables of shell". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to name the variable of shell"!
1. Naming of variables
1) only English, numbers and underscores can be used, starting with English and underscores.
2) cannot repeat the name of the known environment variable in the system
In fact, languages can be compared, Python also has such a requirement, you can think about it.
two。 Assignment of variables
Assignment:
Variables can be assigned in the following ways:
Var=value
The Var event quantity name value is the value assigned to the variable.
[root@xuegod60 ~] # Xero3
[root@xuegod60 ~] # echo $x
three
If the value does not contain any white space characters, such as spaces, then
It does not need to be referenced in quotation marks, otherwise it must use single or double quotes.
Here is a common mistake to pay attention to:
Var = value is the same as var=value
3. Special variable
$# number of parameters
The location of the parameter passed by $n, if $1 is the first value of the parameter passed by the script.
$0 script name
$? The last command execution status returned a value, 0 is correct, non-0 is an error.
Shell script example: vim xinsz08.sh
#! / bin/bash
If [$#-ne 2]
Then
Echo "$0 agre1 agre2"
Exit 1
Fi
Echo $1 $2
Echo $?
Execute script sh + x xinsz08.sh add
The output is as follows:
[root@localhost sh] # sh xinsz08.sh add
Xinsz8.sh agre1 agre2
In the above result, canshu.sh corresponds to $0 in canshu.sh, so you need to enter two error prompts because there is only one passed parameter.
Execute script sh xinsz08.sh add edd
[root@localhost sh] # sh xinsz08.sh add edd
Add edd
0
The above results are normal add edd corresponding to $1 and $2.
0 corresponding to $? Indicates that script execution is normal.
4. Variables and 'quotation marks'
Axiom 123
Caterpillar a
Baked 245 million dollars
D = "245rooma"
Example description: vim test1.sh
#! / bin/bash
Axiom 123
Caterpillar a
Baked 234 million dollars.
D = "234rooma"
Echo "caterpillar c"
Echo "baked goods"
Echo "dwindling"
Execute the script sh test1.sh to output the echo result as follows:
Cobb 123
Bust 234rooma
Ditto 234o123
The quotation marks are:
Single quotation marks are WYSIWYG
D = "234quotation a" double quotation marks are used to make special symbols take effect, such as the $a variable.
Add:
Shell has two types of variables: temporary and permanent.
Temporary variable: defined within the shell program, its use is limited to the program that defines it, and is not visible to other programs.
Permanent variables are environment variables whose values do not disappear with the end of the execution of the shell script.
At this point, I believe you have a deeper understanding of "how to name the variable of shell". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.