I would like to write a function in bash that takes two array parameters like this:
#!/bin/bash
function RemoveElements
{
# $1 and $2 are supposed to be arrays
# This function should generate a new array, containing
# all elements from $1 that did not occur in $2
}
a=(1 3 5 7 8)
b=(2 3 6 7)
c=RemoveElements $a $b
# or perhaps: (if directly returning non-integer
# values from function is not possible)
c=$(RemoveElements $a $b)
# c should now be (1 5 8)
Is this possible and if yes, what is the correct syntax? Both when calling the function, as well as inside the function to process the arrays?
declare -pandprintf "%q") and pass one array in one argument. You can pass one array using stdin and the other using arguments.bash. All you can do is pass each element of an array as a separate argument, or pass the name of an array as a value (which then requires some hoops to access the global variable by that name).