Is there a way to do something like PHPs $array[] = 'foo';
$array[] = 'foo';
(有没有办法像PHP一样$array[] = 'foo';)
(在bash vs做:)
array[0] = 'foo' array[1] = 'bar'
Yes there is:
(就在这里:)
ARRAY=() ARRAY+=('foo') ARRAY+=('bar')
Bash Reference Manual :
(Bash参考手册 :)
In the context where an assignment statement is assigning a value to a shell variable or array index (see Arrays), the '+=' operator can be used to append to or add to the variable's previous value. (在赋值语句为外壳变量或数组索引赋值的上下文中(请参见Arrays),可以使用'+ ='运算符来追加或添加到变量的先前值。)
In the context where an assignment statement is assigning a value to a shell variable or array index (see Arrays), the '+=' operator can be used to append to or add to the variable's previous value.
(在赋值语句为外壳变量或数组索引赋值的上下文中(请参见Arrays),可以使用'+ ='运算符来追加或添加到变量的先前值。)
2.1m questions
2.1m answers
60 comments
57.0k users