I have a function to check if something is in an array:
function inArray() {
local val="$1"
shift
local array=("$@")
for i in "${array[@]}"; do
if [ "${i}" == "${val}" ]; then
return 0
fi
done
return 1
}
And an if statement to try to insert values into noDupe only if it doesn't already have that value:
noDupe=()
values=("test" "test" "test2")
for value in ${values[@]}; do
if [ $(inArray "${value}" "${values[@]}") -eq 1 ]; then
noDupe+="{value}"
fi
done
My current error is that -eq expects a unary operator. I've tried changing it to a == but that's just for strings and not the 0s and 1s my function is returning. How can I get the if statement to work?