Create the constants variable
From Linux Shell Scripting Tutorial - A Beginner's handbook
- You can create the constants variables using the readonly command or declare command.
- The readonly buitin syntax is as follows:
readonly var readonly varName=value
- The declare builtin syntax is as follows:
declare -r var declare -r varName=value
Example
- Create a constant variable called DATA and make its value always the same throughout the shell script i.e. it can't be changed:
readonly DATA=/home/sales/data/feb09.dat echo $DATA /home/sales/data/feb09.dat DATA=/tmp/foo # Error ... readonly variable
- You cannnot unset (delete) the readonly variable:
unset DATASample outputs:
bash: unset: DATA: cannot unset: readonly variable