"Go" based on the use of variable declaration declare under Linux

Source: Internet
Author: User

Transferred from: http://techcurtman.iteye.com/blog/1249512

Declare

Function Description: Declare the properties of the variable, if using declare, then there are no parameters, then bash will actively transfer all the variable name and content, just as set.

Syntax: Declare [-AIXR] Variable

Parameter description:
-A: Defines the following variable as an array
-I: Defines the following variavle as an integer number
-X: Using the same as export, it is to turn the back variable into an environment variable
-r: A variable is also set to read-only, read variables can not change the content, nor unset

eg
1. Sum the variable sum to 200+400
[[Email protected] ~] #sum =200+400
[[Email protected] ~] #echo $sum
200+400--------Here is not as we would expect the result 600, but 200+400, this is because it is a literal type of variable property
[[Email protected] ~] #declare-I sum=200+400
[[Email protected] ~] #echo $sum
Well ,------------understand.
2. Turn sum into an environment variable
[[Email protected] ~] #declare-X sum
3. Make sum a read-only property and cannot be changed
[[Email protected] ~] #declare-R sum
[[Email protected] ~] #sum =apple
-bash:sum:readonly variable
[[Email protected] ~] #unset sum
-bash:unset:sum:cannot unset:readonly Variable
Here is a special note: After declaring a read-only variable, you cannot modify the variable's properties or delete the variable, so when declaring a variable, you should use caution and avoid having to go back. Also, when you knock ReadOnly in the command line, you will find that there are many read-only variables, and of course these variables cannot be modified or deleted.

"Go" based on the use of variable declaration declare under Linux

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.