From the perspective of programming language, the use of linuxshell-Variables
Source: Internet
Author: User
From the perspective of programming language, let's look at the use of linuxshell-variables-general Linux technology-Linux programming and kernel information. The following is a detailed description. Author: Filia. Tao
Shell language discussed in BASH
From the programming language perspective, the role of variables is very important.
1. Variable Declaration
General variables do not need to be declared, or use the declare variable name
2. Variable assignment
Variable name = value or declare variable name = value (Note that there cannot be spaces on both sides of "=)
3. constant problems
Generally, there is no constant, but there are read-only variables. You can use the readonly variable name or the declare-r variable name to set the read-only variable. In some books, read-only variables can be assigned a value and cannot be cleared (or deleted ). However, I tried to avoid assigning a value again.
4. Clear Variables
Unset variable name?
5. variable value reference $ variable name (that is, the variable value can be referenced by adding a "$" symbol before the variable name) if necessary, you can add curly brackets (for example, $ {num}) to the variable name })
The relationship between variables and their values must be distinguished. "$" must be added only when the value of the variable is referenced, and the variable is assigned a value, you cannot add "$" When declaring variables ".
Easy to make mistakes
1. The above value assignment method only applies to the value assignment between values. It cannot be used to assign values to variables such as the return of other functions and command output. In this case, you need to use anti-reference, command replacement, and other methods.
2. the name of a common variable is similar to that of a common programming language (including letters, numbers, and underscores). However, you can often see symbols such as $1, $2, $ *, and $, these are location variables and other special variables, which have special usage and usage.
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