简体   繁体   中英

String replacement (to lowercase) in Bash 4.3.33 - bad substitution error

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 ( ch ange sh ell) command

chsh -s /opt/local/bin/bash

基于对我的评论的评论,这是答案:

echo $a | tr '[:upper:]' '[:lower:]'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM