ZSH 的这个功能(我猜)被用在答案中使用多个字符作为分隔符分割字符串的 ZSH 语法
或者您可以使用带有 $=var 的 IFS 拆分:
IFS=.- parts=( $=file )
您能指出 ZSH 文档中该构造的名称吗?
答案1
答案2
如果您询问的是$=file
而不是数组分配parts=( ... )
,它记录在参数扩展节(或等效于man zshexpn
),从开始的小节开始${#spec}
${=spec} Perform word splitting using the rules for SH_WORD_SPLIT during the evaluation of spec, but regardless of whether the parameter appears in double quotes; if the `=' is doubled, turn it off. This forces parameter expansions to be split into separate words before substitution, using IFS as a delimiter. This is done by default in most other shells.
“裸”形式$=spec
的解释如下${#spec}
:
If the option POSIX_IDENTIFIERS is not set, and spec is a simple name, then the braces are optional; this is true even for spe‐ cial parameters so e.g. $#- and $#* take the length of the string $- and the array $* respectively. If POSIX_IDENTIFIERS is set, then braces are required for the # to be treated in this fashion.