[Shell] Bash variables: Custom variables

Source: Internet
Author: User

/*-------------------------------------------------------------------------------------------

@ Black eyed poet <www.farwish.com>

--------------------------------------------------------------------------------------------*/

A variable is a unit of computer memory where the stored value can be changed. Variables are used to temporarily save information.

I. Variable setting rules

1. Numbers, letters, underscores, cannot start with numbers.

2.the default type of variables in bash is string type , and if you want to perform numeric operations, you must specify the variable type as numeric.

3. The variable is connected with an equal sign and cannot have spaces around the equals sign.

4. If a variable has a space, either single or double quotation marks are required, because the space represents the separator.

 Name= "Chen Wei"

5. In the value of the variable, you can use the "\" escape character.

6. If you need to increase the value of the variable, then you can stack the value of the variable. However, variables need to contain "$ variable name" or ${variable name} in double quotation marks.

7. If you assign the result of the command as a variable value , you need to use the back quotation mark or the $ () containing command.

name=' ls ' or name=$ (LS)

Echo $name

8. The environment variable name is recommended capitalization, easy to distinguish.

Two. Variable classification

1. User-defined variables (also called local variables).

2. Environment variables: The data stored in the variable is related to the operating environment of the system. (value cannot be changed, can be created)

3. Positional parameter variables: used to pass parameters or data to the script, the variable name cannot be customized, the variable function is fixed. (name cannot be customized, cannot be created, can only be changed)

4. Predefined variables: The variables that are already defined in bash, variable names cannot be customized, and variables are fixed. (name cannot be customized, cannot be created, can only be changed)

Name=chenwei #变量赋值

echo $name #变量调用 (Chenwei)

Name="$name"is #变量叠加

echo $name #变量调用 (Chenweiis)

Name=${name}poet #变量叠加

echo $name #变量调用 (Chenweiispoet)

Set #变量查看

unset name #变量删除

Link:http://www.cnblogs.com/farwish/p/3923622.html

[Shell] Bash variables: Custom variables

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.