Shell Programming-Variables (iii)

Source: Internet
Author: User

In shell scripts, variables are divided into two types, system variables, and custom variables.
System default variables are some of the system's own variables, such as PATH variable
User-defined variables are some of the variables that you define when you write the script

Variable name naming rules
The first character must be the letter "A-Z and a-Z"
The middle cannot have spaces, but you can use the underscore "_"
Punctuation cannot be used
Cannot use keywords in bash
There can be no spaces between the variable name and the equals sign

Read-only variables
Use the readonly command when defining a variable as a read-only variable

Edit the file as follows:

The results are as follows:


Delete a variable
Delete using the unset command
Syntax: unset variable name
The variable cannot be used again after it is deleted, and unset cannot delete the read-only variable, and the value of the read-only variable cannot be changed


Using variables with $
In shell programming, so the variable is composed of strings, and does not need to declare the type of the variable beforehand, it supports the only type of variable is the string
When using a defined variable, simply add "$" to the variable name before

Edit the text as follows:

  

The results are as follows:

·

The curly braces outside the variable name are optional, plus the curly braces help to read the understanding and the interpreter is the boundary of the variable
For example, the variable is hello_name
echo "This is $hello _nameandtynam"
echo "This is ${hello_name}andtynam"

The first tries to hello_nameandtynam the most variable, and the second is to use Hello_name as the variable

Shell Programming-Variables (iii)

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.