If your target shells support arrays (ksh, bash, zsh), then you may be better off using an array:args=(-a -l)ls "${args[@]}"来自 zsh 常见问题:2.1:与 sh 和 ksh 的区别经典的区别是分词,在问题 3.1 中讨论;这吸引了很多刚开始使用 zsh 的用户. The classic difference is word splitting, discussed in question 3.1; this catches out very many beginning zsh users.3.1: 为什么 $var where var="foo bar" 不行我期望什么? 是涵盖此问题的常见问题解答.3.1: Why does $var where var="foo bar" not do what I expect? is the FAQ that covers this question.来自zsh手册:14.3 参数扩展请特别注意,除非设置了选项 SH_WORD_SPLIT,否则未引用参数的单词不会自动在空格上拆分;有关更多详细信息,请参阅下面对此选项的参考.这是与其他 shell 的重要区别. Note in particular the fact that words of unquoted parameters are not automatically split on whitespace unless the option SH_WORD_SPLIT is set; see references to this option below for more details. This is an important difference from other shells.SH_WORD_SPLIT导致对不带引号的参数扩展执行字段拆分. Causes field splitting to be performed on unquoted parameter expansions. 这篇关于zsh 中的变量扩展与 bash 中的不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-22 18:22