我发现这个在prezto
源代码:zsh的神秘变量扩展
# Set the command name, or in the case of sudo or ssh, the next command.
local cmd="${${2[(wr)^(*=*|sudo|ssh|-*)]}:t}"
我一直在读zsh doc了很多,但还是一无所获靠近这是怎么回事。在shell本身的实验中,它似乎表明[]
是一些算术的东西,这很有道理,但我没有看到解释(w)
应该如何工作的部分。这似乎是一个适用于数学表达式一些神奇的运营商......
[email protected] ~/.zprezto ❯❯❯ VAR="one two three four"
[email protected] ~/.zprezto ❯❯❯ echo ${VAR[2]}
n
[email protected] ~/.zprezto ❯❯❯ echo ${VAR[(w)2]}
two
[email protected] ~/.zprezto ❯❯❯ echo ${VAR[(w)]}
zsh: bad math expression: empty string
[email protected] ~/.zprezto ❯❯❯
http://zsh.sourceforge.net/Doc/Release/Parameters.html#Array-Subscripts – melpomene
http://zsh.sourceforge.net/Doc/Release/Parameters.html#Subscript-Flags – melpomene