zsh 参数扩展语法:结合默认值和转换为大写
zsh parameter expansion syntax: combining default value and conversion to upper case
在 zsh
脚本中,
echo ${X:-4711}
输出变量X的值,如果有none则输出4711。
echo ${X:u}
输出变量 X 的值,转换为大写。
请问有没有办法将两者结合起来,即达到
的效果
tmp=${X:-4711}
echo $X:u
不引入辅助变量
$ echo ${${X:-4711}:u}
4711
$ X=hello
$ echo ${${X:-4711}:u}
HELLO
来自man zshexpn
:
If a `${...}` type parameter expression or a `$(...)` type command
substitution is used in place of name above, it is expanded first and
the result is used as if it were the value of name. Thus it is possible
to perform nested operations: `${${foo#head}%tail}` substitutes the value
of `$foo` with both 'head' and 'tail' deleted.
在 zsh
脚本中,
echo ${X:-4711}
输出变量X的值,如果有none则输出4711。
echo ${X:u}
输出变量 X 的值,转换为大写。
请问有没有办法将两者结合起来,即达到
的效果tmp=${X:-4711}
echo $X:u
不引入辅助变量
$ echo ${${X:-4711}:u}
4711
$ X=hello
$ echo ${${X:-4711}:u}
HELLO
来自man zshexpn
:
If a `${...}` type parameter expression or a `$(...)` type command substitution is used in place of name above, it is expanded first and the result is used as if it were the value of name. Thus it is possible to perform nested operations: `${${foo#head}%tail}` substitutes the value of `$foo` with both 'head' and 'tail' deleted.