zsh参数扩展语法:将默认值和转换结合为大写

时间:2016-01-04 12:32:48

标签: linux shell unix zsh

zsh脚本中,

echo ${X:-4711}

输出变量X的值,如果没有则输出4711。

echo ${X:u}

输出变量X的值,转换为大写。

我想知道,是否有办法将两者结合起来,即具有

的效果
tmp=${X:-4711}
echo $X:u

不引入辅助变量。

1 个答案:

答案 0 :(得分:3)

{{1}}

来自{{1}}:

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.