builtin
Bash readonly — prevent reassignment
Marks scalar variables readonly, optionally assigning a value. Subsequent reassignment or unset is rejected in the current shell.
Formal Syntax & Structure
bash syntaxbash
readonly name[=value] ...Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name[=value] | string | Variable name with optional initial value. |
Return Value
exit status
Zero on success, nonzero for invalid assignment or other error.
Working Example
Example Snippetbash
readonly app_name='ByteMind'printf '%s\n' "$app_name"declare -p app_name