Transforming
I only discovered courtesy of ostechnix’s tutorial that Bash offers two ways of doing case conversion:
Lowercasing
${varname@L}
or
${varname,,}
ExampleGroup 'from https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html'
# also https://opensource.com/article/17/6/bash-parameter-expansion
# https://stackoverflow.com/questions/40732193/bash-how-to-use-operator-parameter-expansion-parameteroperator
Example 'lower to upper ${parameter@U}'
foo="bar"
When call echo "${foo@U}"
The output should eq "BAR"
End
Example 'lower to upper ${parameter^^}'
foo="bar"
When call echo "${foo^^}"
The output should eq "BAR"
End
Example 'Title lower case ${parameter@u}'
foo="bar"
When call echo "${foo@u}"
The output should eq "Bar"
End
Example 'Title lower case ${parameter^}'
foo="bar"
When call echo "${foo^}"
The output should eq "Bar"
End
Example 'upper to lower ${parameter@L}'
foo="BAR"
When call echo "${foo@L}"
The output should eq "bar"
End
Example 'upper to lower ${parameter,,}'
foo="BAR"
When call echo "${foo,,}"
The output should eq "bar"
End
Example 'First letter to lower ${parameter,}'
foo="BAR"
When call echo "${foo,}"
The output should eq "bAR"
End
Example 'Transpose case ${parameter~~}'
foo="bAR"
When call echo "${foo~~}"
The output should eq "Bar"
End
Example 'Transpose first letter ${parameter~}'
foo="bar"
When call echo "${foo~}"
The output should eq "Bar"
End
Example 'associative array JSON path'
foo=""performer",0,"sameAs",0"
When call echo "${foo}"
The output should eq "performer,0,sameAs,0"
End
# Output to be reused as input of another command
Example '${parameter@operator} Q'
foo=""performer",0,"sameAs",0"
When call echo "${foo@Q}"
The output should eq "'performer,0,sameAs,0'"
End
Example '${parameter@operator} a'
declare -A arr=(["foo"]="bar")
When call echo "${arr@a}"
The output should eq "A"
End
Example '${parameter@operator} K'
declare -A arr=([""performer",0,"sameAs",0"]="bar")
When call echo "${arr[@]@K}"
The output should eq "performer,0,sameAs,0 \"bar\" "
End
Example '${parameter@operator} k'
declare -A arr=([""performer",0,"sameAs",0"]="bar")
When call echo "${arr[@]@k}"
The output should eq "performer,0,sameAs,0 bar"
End
End