Wednesday, December 14, 2011

Using Read-Only Constants in Unix Shell Scripts

You can use typeset -r to make variables in a ksh script be read-only. This effectively makes them constants, which can no longer be modified.

For example:

[550]-> pi=3.14159

[551]-> echo $pi

3.14159

[552]-> typeset -r pi

[553]-> pi=45


ksh: pi: is read only

[554]-> echo $pi


3.14159

0 comments: