0

I'm writing a pre-rebase hook for Git using bash script and I need to convert a string to lowerCase or UperCase. I tried some methods doumented in Bash reference

example:

 myString="AbcDFmk";
 echo ${myString,,}

and this is the result: ${myString,}: bad substitution

Can you please help me to find a way to do this?

2
  • Works here (Ubuntu 14.04, GNU bash, Version 4.3.11(1) ) - what's your bash version? – Eugen Rieck Sep 18 '15 at 9:47
  • Use tr. Example $ echo "Hello World" | tr "[:upper:]" "[:lower:]" – DavidPostill Sep 18 '15 at 9:47
1

The Bash reference you mention is for Bash version 4.3. String substitutions are not supported in 3.1.

You can use tr like this:

echo $(tr '[:upper:]' '[:lower:]'<<<${myString})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.