user1308345
user1308345

Reputation: 1112

What does 2 commas after variable name mean in bash?

Recently I came across this syntax:

${reportName,,}

I could not find anything by googling, so does anyone know what does those ,, mean?

Upvotes: 72

Views: 16779

Answers (2)

P....
P....

Reputation: 18391

This is called "Parameter Expansion" available in bash version 4+ . To change the case of the string stored in the variable to lower case.Eg:

var=HeyThere
echo ${var,,}
heythere

You may want to try some additional commands and check the effect:

${var^}
${var^^}
${var,}
${var,,}

Note: "Parameter Expansion" is present in man bash .Search for it.

https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion

Upvotes: 80

scrow
scrow

Reputation: 447

As mentioned by P... this is parameter expansion. Examples below.

myword="Hello"
echo ${myword^}  # first letter uppercase
echo ${myword^^} # all uppercase
echo ${myword,}  # first letter lowercase
echo ${myword,,} # all lowercase
echo ${myword~}  # reverses the case for the first letter
echo ${myword~~} # reverses the case for every letter

Output:

Hello
HELLO
hello
hello
hello
hELLO

Upvotes: 10

Related Questions