I'm trying to change uppercase to lowercase using string replacement in bash, but i'm getting a bad substitution error.
> a=HEY
> echo $a
HEY
> echo ${a,,}
-bash: ${a,,}: bad substitution
# desired output is hey
I've seen similar questions to this, but in most cases it was down to using an earlier version of bash. I'm using GNU bash 4 and still having the same problems.
> bash --version
GNU bash, version 4.3.33(1)-release (x86_64-apple-darwin14.1.0)
This is a Mac thing maybe? Any help would be appreciated.
Looks like the bash that is first in PATH
happens to be 4.3.33, but the bash you're running in the interactive session is probably an older version. Run echo "$BASH_VERSION"
to check.
If the above is correct, run
type bash
to see the path of the newer version, probably something like /opt/local/bin/bash
. I'll assume it is. If you want that to be your login shell, first add it to /etc/shells
sudo -e /etc/shells
After that, users are allowed to select that as their login shell by using the chsh
(change shell) command
chsh -s /opt/local/bin/bash
Based on the comments on my comment, this is the answer:
echo $a | tr '[:upper:]' '[:lower:]'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With