Skip to main content
deleted 2 characters in body
Source Link
cas
  • 85.1k
  • 9
  • 139
  • 207

Adding an array to another array is pretty straight-forward:

$ a=(1 2 3) $ b=(4 5 6) $ a+=("${b[@]}") $ typeset -p a declare -a a=([0]="1" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6") 

If you're doing relatively complicated things with arrays, though, you really should use a language more suited to the task. awk or perl, for example. Or python. Or pretty much anything except bash or other shells.

A shell is good for orchestrating the execution of other programs (and pipelines of other programs, and redirection of stdin and stdout, etc) to do things or to process data. It is not good at doing those other tasks itself - in fact, it is terrible at it.

awk has multi-dimensional arrays (both indexed and associative), perl does too and also has data structures where arrays or hashes can contain other arrays and/or hashes, nested arbitrarily deep. Most other languages also have complex data structures.

And, just as importantly, they don't have the quoting or word-splitting issues that shells do.

Adding an array to another array is pretty straight-forward:

$ a=(1 2 3) $ b=(4 5 6) $ a+=("${b[@]}") $ typeset -p a declare -a a=([0]="1" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6") 

If you're doing relatively complicated things with arrays, though, you really should use a language more suited to the task. awk or perl, for example. Or python. Or pretty much anything except bash or other shells.

A shell is good for orchestrating the execution of other programs to do things or to process data. It is not good at doing those other tasks itself - in fact, it is terrible at it.

awk has multi-dimensional arrays (both indexed and associative), perl does too and also has data structures where arrays or hashes can contain other arrays and/or hashes, nested arbitrarily deep. Most other languages also have complex data structures.

And, just as importantly, they don't have the quoting or word-splitting issues that shells do.

Adding an array to another array is pretty straight-forward:

$ a=(1 2 3) $ b=(4 5 6) $ a+=("${b[@]}") $ typeset -p a declare -a a=([0]="1" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6") 

If you're doing relatively complicated things with arrays, though, you really should use a language more suited to the task. awk or perl, for example. Or python. Or pretty much anything except bash or other shells.

A shell is good for orchestrating the execution of other programs (and pipelines of other programs, and redirection of stdin and stdout, etc) to do things or to process data. It is not good at doing those other tasks itself - in fact, it is terrible at it.

awk has multi-dimensional arrays (both indexed and associative), perl does too and also has data structures where arrays or hashes can contain other arrays and/or hashes, nested arbitrarily deep. Most other languages also have complex data structures.

And, just as importantly, they don't have the quoting or word-splitting issues that shells do.

deleted 2 characters in body
Source Link
cas
  • 85.1k
  • 9
  • 139
  • 207

Adding an array to another array is pretty straight-forward:

$ a=(1 2 3) $ b=(4 5 6) $ a+=( "${b[@]}" ) $ typeset -p a declare -a a=([0]="1" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6") 

If you're doing relatively complicated things with arrays, though, you really should use a language more suited to the task. awk or perl, for example. Or python. Or pretty much anything except bash or other shells.

A shell is good for orchestrating the execution of other programs to do things or to process data. It is not good at doing those other tasks itself - in fact, it is terrible at it.

awk has multi-dimensional arrays (both indexed and associative), perl does too and also has data structures where arrays or hashes can contain other arrays and/or hashes, nested arbitrarily deep. Most other languages also have complex data structures.

And, just as importantly, they don't have the quoting or word-splitting issues that shells do.

Adding an array to another array is pretty straight-forward:

$ a=(1 2 3) $ b=(4 5 6) $ a+=( "${b[@]}" ) $ typeset -p a declare -a a=([0]="1" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6") 

If you're doing relatively complicated things with arrays, though, you really should use a language more suited to the task. awk or perl, for example. Or python. Or pretty much anything except bash or other shells.

A shell is good for orchestrating the execution of other programs to do things or to process data. It is not good at doing those other tasks itself - in fact, it is terrible at it.

awk has multi-dimensional arrays (both indexed and associative), perl does too and also has data structures where arrays or hashes can contain other arrays and/or hashes, nested arbitrarily deep. Most other languages also have complex data structures.

And, just as importantly, they don't have the quoting or word-splitting issues that shells do.

Adding an array to another array is pretty straight-forward:

$ a=(1 2 3) $ b=(4 5 6) $ a+=("${b[@]}") $ typeset -p a declare -a a=([0]="1" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6") 

If you're doing relatively complicated things with arrays, though, you really should use a language more suited to the task. awk or perl, for example. Or python. Or pretty much anything except bash or other shells.

A shell is good for orchestrating the execution of other programs to do things or to process data. It is not good at doing those other tasks itself - in fact, it is terrible at it.

awk has multi-dimensional arrays (both indexed and associative), perl does too and also has data structures where arrays or hashes can contain other arrays and/or hashes, nested arbitrarily deep. Most other languages also have complex data structures.

And, just as importantly, they don't have the quoting or word-splitting issues that shells do.

Source Link
cas
  • 85.1k
  • 9
  • 139
  • 207

Adding an array to another array is pretty straight-forward:

$ a=(1 2 3) $ b=(4 5 6) $ a+=( "${b[@]}" ) $ typeset -p a declare -a a=([0]="1" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6") 

If you're doing relatively complicated things with arrays, though, you really should use a language more suited to the task. awk or perl, for example. Or python. Or pretty much anything except bash or other shells.

A shell is good for orchestrating the execution of other programs to do things or to process data. It is not good at doing those other tasks itself - in fact, it is terrible at it.

awk has multi-dimensional arrays (both indexed and associative), perl does too and also has data structures where arrays or hashes can contain other arrays and/or hashes, nested arbitrarily deep. Most other languages also have complex data structures.

And, just as importantly, they don't have the quoting or word-splitting issues that shells do.