I'm trying to understand if `declare -c var` is a reliable way to lowercase all letters in a phrase except for the first letter. It seems like that's what it does, but I came across some conflicting information suggesting that it lower-cases all letters instead. Also, I can't find any official documentation about a `-c` option for `declare`. Can anyone clarify this?
1 Answer
Actually, `declare -c` isn't a recognized command in bash. For more info, check the official documentation. If you need to lowercase a string, use the `-l` option for `declare`. There's actually a better way to achieve your goal: use `var="${var,,}"` to lowercase everything and `var="${var^}"` to capitalize just the first letter. Both methods are well documented and might be clearer for others reading your code.
That's clear, thanks for the alternative! I appreciate the suggestion as I'm trying to avoid any undocumented options that could confuse others.