Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash function parameter construction ${1,,}

In a script I found, I see this construction:

is_true() {
  local var=${1,,} 
  ...

As I understand it is some kind of parameter passing. $1,$2,$# I understand but what ${1,,} stands for?

like image 318
Sergey Gerbek Avatar asked Oct 25 '17 06:10

Sergey Gerbek


1 Answers

This ( ${1,,}) is called "Parameter Expansion" available in bash version 4+ . Here it is used to change the case of the string stored in the variable, In this case first argument to the script.

Some examples: Lower case conversion.

x='HellO'
echo ${x}
HellO
echo ${x,,}
hello

To convert $x into upper case.

echo ${x^^}
HELLO

To invert the case:

x='Hey there'
echo ${x~~}
hEY THERE
like image 145
P.... Avatar answered Sep 19 '22 16:09

P....