Bash building a function parameter $ {1,}

In the script I found, I see this construct:

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

As I understand it, this is some kind of transmission parameter. $ 1, $ 2, $ # I understand, but what does $ {1,} mean?

+4
source share
1 answer

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

Some examples: Lowercase conversion .

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

Convert $xto uppercase .

echo ${x^^}
HELLO

In invert case:

x='Hey there'
echo ${x~~}
hEY THERE
+4
source

Source: https://habr.com/ru/post/1688117/


All Articles