- Variables
- Valid Characters
- Scalar
- Array
- Read-Only
- Unsetting
- What's Next
Unsetting
When going through the examples earlier in the chapter, the variable Children was used several times. What was not shown was the command that was run in between to free up that variable so it could be used again. Here is a more complete listing of commands to let you see what was really going on:
$ echo ${Children[*]} Meshia Andy Ashley Tommy $ unset Children $ echo ${Children[*]} $
As you can see from the previous code, the unset command is followed by the variable to be freed. If the variable's value is not freed from memory, it cannot be set to something else. But, what about when you made Children a read-only variable? How do you get rid of it?
The quick answer is that you cannot. If you could, it would go against the basic idea of identifying the variable as crucial and unchangeable.
The long answer is that the variable will remain as long as the shell or program environment of which it is a part exists. Therefore, a variable that is set as a part of the environment, such as KSH_VERSION in the following example or the variable Children that you set earlier to be readonly, remains part of the environment until that environment goes away:
$ readonly # Displays all readonly variables Children KSH_VERSION
If a new environment is instantiated, that new environment will not have the variable Children. It will have the variable KSH_VERSION instead because it is set with each new login. This is shown in the next example:
$ su - dennis Password: $ readonly KSH_VERSION
When the environment in the previous code is exited, and the previous environment is back in control, the read-only variable Children again returns:
$ exit $ readonly Children KSH_VERSION
After the environment that contains the variable Children is terminated, the variable is released from memory.