Array - Add new elements to an array using linux terminal
In this article we can learn how to add/create new elements in an array push elements to a array without elements index in linux terminal bash.
Push elements to a array without elements index
On linux shells arr[0]="new" and arr[1]="newest" methods are not available and arrays should start with indext 0.
method1) specify the index value
1 arr=( new user create )
2 arr[3]="eos"
3 echo "${arr[@]}"
method2) without the index value
1 arr=( new user create )
2 arr+=("eos")
3 arr+=("ltc")
4 echo "${arr[@]}"
method3) without the index value
1 arr=( new user create )
2 arr=("${arr[@]}" "one")
3 arr=("${arr[@]}" "two")
4 echo "${arr[@]}"