Linux zsh参数扩展语法:结合默认值和转换为大写
在Linux zsh参数扩展语法:结合默认值和转换为大写,linux,shell,unix,zsh,Linux,Shell,Unix,Zsh,在zsh脚本中 echo ${X:-4711} 输出变量X的值,如果没有,则输出4711 echo ${X:u} 输出变量X的值,转换为大写 我想知道,是否有办法将两者结合起来,即产生 tmp=${X:-4711} echo $X:u 没有引入辅助变量 $ echo ${${X:-4711}:u} 4711 $ X=hello $ echo ${${X:-4711}:u} HELLO 从手册zshexpn: If a `${...}` type parameter express
zsh
脚本中
echo ${X:-4711}
输出变量X的值,如果没有,则输出4711
echo ${X:u}
输出变量X的值,转换为大写
我想知道,是否有办法将两者结合起来,即产生
tmp=${X:-4711}
echo $X:u
没有引入辅助变量
$ echo ${${X:-4711}:u}
4711
$ X=hello
$ echo ${${X:-4711}:u}
HELLO
从手册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.
如果是`${…}`类型参数表达式或`$(…)`类型命令
替换用于替换上面的名称,它首先展开,然后
结果的使用就好像它是name的值一样。因此这是可能的
要执行嵌套操作:`${${foo#head}%tail}`替换该值
同时删除“head”和“tail”的“$foo”的。