I was playing around with Bash variables and mistakenly used the -c
option (for const
) to declare
instead of the correct -r
option to create a readonly
variable. To my surprise, the variable retained the -c
attribute and capitalized the first letter of whatever value I assigned.
This behavior is not listed in declare
's usage, either within the declare --help
output or on Bash's info page. It seems to be incompatible with ksh's typeset
, though the -u
and -l
options are compatible.
Is this a well-known undocumented feature? Is it generally available?
declare -c
, -l
, and -u
appear to have been added all together in bash 4.0 (introduced in 4.0-rc1), as long as the --enable-casemod-attributes
configure flag isn't disabled (it's enabled by default). There are tests for them (in tests/casemod.tests
). Why -c
was never documented is a mystery.