Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 623
A-K Avatar asked Apr 24 '15 19:04

A-K


2 Answers

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
like image 97
geirha Avatar answered Nov 15 '22 23:11

geirha


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

echo $a | tr '[:upper:]' '[:lower:]'
like image 29
kecso Avatar answered Nov 15 '22 23:11

kecso