Changing line (lowercase) in Bash 4.3.33 - incorrect replacement error

I am trying to change upper case to lower case using string substitution in bash, but I am 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 most of the time it didn't use an earlier version of bash. I am using GNU bash 4 and am still having the same problems.

> bash --version
GNU bash, version 4.3.33(1)-release (x86_64-apple-darwin14.1.0)

      

Could it be a Mac? Any help would be appreciated.

+3


source to share


2 answers


It looks like the bash that is first in PATH

will be 4.3.33, but the bash you are using in an interactive session is probably an older version. Run echo "$BASH_VERSION"

to check.

If this is true, run

type bash

      

to see the path to a newer version, maybe something like /opt/local/bin/bash

. I guess that's the way it is. If you want this to be your login shell, first add it to / etc / shells



sudo -e /etc/shells

      

After that, users are allowed to select this as their login shell using the command chsh

( ch ange sh ell)

chsh -s /opt/local/bin/bash

      

+2


source


Based on the comments on my comment, this is the answer:



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

      

0


source







All Articles