该猛砸手册说:
SIMPLE COMMAND EXPANSION
When a simple command is executed, the shell performs the following
expansions, assignments, and redirections, from left to right.
[...]
4. The text after the = in each variable assignment undergoes tilde
expansion, parameter expansion, command substitution, arithmetic
expansion, and quote removal before being assigned to the variable.
括号扩展不在列表中,因此未对赋值执行v={a,b}-{1,2}
。如@Wildcard所述,v=a-1 v=b-1 ...
无论如何,简单的扩展到都是毫无意义的。
同样,执行时echo $v
,以下条件适用:
EXPANSION
Expansion is performed on the command line after it has been split
into words. [...]
The order of expansions is: brace expansion; tilde expansion,
parameter and variable expansion, arithmetic expansion, and command
substitution (done in a left-to-right fashion); word splitting; and
pathname expansion.
括号扩展发生在变量扩展之前,因此分配给的括号$v
不会扩展。
但是您可以执行以下操作:
$ var_this=foo var_that=bar
$ echo $var_{this,that}
foo bar
以扩大它$(echo ...)
,如果你没有在字符串中的任何空白加以扩展,因此将无法运行与分词的问题应该工作。如果可以的话,更好的方法可能是使用数组变量。
例如,将扩展保存到数组中并使用扩展值运行一些命令:
$ v=( {a,b}-{1,2} )
$ some_command "${v[@]}"
=
。例如,v=a-1 a-2
将不起作用。