"Shell Programming" 2, syntax

Source: Internet
Author: User

First, declaring variables

Myurl= "http://see.xidian.edu.cn/cpp/linux/"
mynum=100

Attention:
There can be no spaces between the variable name and the equals sign, which may be different from any programming language you are familiar with.
At the same time, the name of the variable names must follow the following rules:
The first character must be a letter (a-z,a-z).
You can use an underscore (_) without spaces in the middle.
Punctuation cannot be used.
You can't use the keywords in bash (you can see the reserved keywords using the help command).

Ii. Use of variables

Echo ${your_name}
Note: It is a good programming practice to add curly braces to all variables.

Third, redefine variables

Myurl= "http://see.xidian.edu.cn/cpp/linux/"
Echo ${myurl}
Myurl= "http://see.xidian.edu.cn/cpp/shell/"
Echo ${myurl}

Note: The second assignment cannot be written $myUrl = "http://see.xidian.edu.cn/cpp/shell/" and the dollar sign ($) is used when using variables.

Four, read-only variables

Myurl= "http://see.xidian.edu.cn/cpp/shell/"
ReadOnly Myurl
Myurl= "http://see.xidian.edu.cn/cpp/danpianji/"

Run the script with the following results:
/bin/sh:name:this variable is read only.

V. Delete variables
The variable cannot be used again after it has been deleted; The unset command cannot delete a read-only variable.
Unset variable_name

Vi. Types of variables
When you run the shell, there are three different variables:
1) Local Variables
Local variables are defined in a script or command, only valid in the current shell instance, and other shell-initiated programs cannot access local variables.
2) Environment variables
All programs, including shell-initiated programs, can access environment variables, and some programs require environment variables to keep them running properly. Shell scripts can also define environment variables when necessary.
3) Shell variables
Shell variables are special variables that are set by the shell program. Some of the shell variables are environment variables, some of which are local variables that guarantee the shell's normal operation.

"Shell Programming" 2, syntax

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.