击:增加价值阵列时不指定一个关键 [英] Bash: add value to array without specifying a key
本文介绍了击:增加价值阵列时不指定一个关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法做这样的事情PHP的 $数组[] ='富';
在bash VS做的:
数组[0] ='富'
阵列[1] ='吧'
解决方案
是的,有:
ARRAY =()
ARRAY + =('富')
ARRAY + =('巴')
在哪里赋值语句赋值给一个shell变量或数组索引(见阵列)的背景下,+ =操作符可以用于追加或添加到变量previous值。
块引用>Is there a way to do something like PHPs
$array[] = 'foo';
in bash vs doing:array[0] = 'foo' array[1] = 'bar'
解决方案Yes there is:
ARRAY=() ARRAY+=('foo') ARRAY+=('bar')
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.
这篇关于击:增加价值阵列时不指定一个关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文