readonly builtin
The builtin that makes a variable unchangeable for the rest of the shell's life, used for constants.
In more detail
Any later attempt to assign it is an error, which catches accidental reuse of a name. The course style puts readonly constants near the top of a script, in capitals.
Example
readonly SOURCE_FILE="poem.txt"Related terms
- declare — The bash builtin that creates variables with attributes: -i integer, -r read-only, -a array, -A associative array, -n name reference, and -p to print.
- global variable — A variable defined at the top level of a program or module, shared by all the code in that process.
Taught in
- Functions, local And declare — Bash Scripting & Command Line Automation
- Style That Prevents Bugs — Bash Scripting & Command Line Automation