最近我遇到了这种语法:
${reportName,,}
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索找不到任何东西,所以有谁知道这些是什么意思?
P..*_*... 30
这称为bash版本4+中的"参数扩展".要将存储在变量中的字符串的大小写更改为小写.Eg:
var=HeyThere
echo ${var,,}
heythere
Run Code Online (Sandbox Code Playgroud)
您可能想尝试一些其他命令并检查效果:source
${var^}
${var^^}
${var,}
${var,,}
Run Code Online (Sandbox Code Playgroud)
注意:"参数扩展"存在于man bash.Search中.
正如 P 所提到的...这是参数扩展。下面的例子。
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
Run Code Online (Sandbox Code Playgroud)
输出:
Hello
HELLO
hello
hello
hello
hELLO
Run Code Online (Sandbox Code Playgroud)