I'm trying to build a function that:
- Gets arguments and assigns them to an array.
- Removes all the elements that match the Exclude file.
Exclude file is a text file that contains a list of strings to exclude separated by lines.
For example:
The Exclude file is: list.txt.
It contains:
value1
value2
Let's assume we call the function with these arguments:
Function value1 value2 value3
The desired output would be:
value3
So far I tried to iterate through the list.txt and overwrite the array with array minus the String from the file. But it seems that it doesn't overwrite the array and instead it appends the values.
The output I get right now is:
value3 value2 value3
My code is:
function Function {
argsArr=( "$@" )
while read p; do
argsArr="${argsArr[@]//$p*/}"
done <list.txt
echo "${argsArr[@]}"
}