Shell Variables(Local)
Shell variables identify the system enviroment, it is convenient to keep useful information.customer settings, and some temporary messages.
Local Variables
Local variables could only be used in user’s current Shell instance.If log out or shutdown the instance, these local variables are invalidate.So, its advantage is that users can not modify the other Shell’s local setting.
The variables of Shell are always included by pairs of {} which mark the inside strings as variables.
Syntax: # variable-name=value
or # {variable-name=value}
The following models are listed for various usage:
1.variable-name=value : identify the varaible with the “value” listed
2.variable-name+value : usring the “value” instead of the former setting.
3.variable-name:?value : if the variable is not defined, then displays customer error messages.
4.variable-name? : if the variable is not defined, then displays the system warning.
5.varible-name:=value : if the variable is not defined, then put “value” to it.
Display variables:
# echo ${variable-name}
# echo variable-name
Clear the setting:
# unset variable-name
Display all the local variables:
# set
The following example is designed to show how to identify whether the variables has been modified or not.
# color=blue
# echo “COLOR is ${color:=grey}”
COLOR is blue
# unset color
# echo “COLOR is ${color=grey}”
COLOR is grey
Using variables to hold some information:
# source = “/test1”
# dest = “/test2”
# cp ${source} ${dest}
Set the variable read only:
# readonly variable-name
Which variables has been configurated as readonly?
# readonly