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