I am using the following code to first split an array into 2 and then search if 2 elements "Alchemist" and "Axe" are present in each of the two split arrays.
tempifs=$IFS
IFS=,
match=($i)
IFS=$tempifs
team1=( "${match[@]:0:5}" )
team2=( "${match[@]:5:5}" )
if [ array_contains2 $team1 "Alchemist" "Axe" ]
then
echo "team1 contains"
fi
if [ array_contains2 $team2 "Alchemist" "Axe" ]
then
echo "team2 contains"
fi
array_contains2 () {
local array="$1[@]"
local seeking=$2
local seeking1=$3
local in=0
for element in "${array[@]}"; do
if [[ $element == $seeking && $element == $seeking1]]
then
in=1
break
fi
done
return $in
}
But I am getting the following error -
/home/ashwin/bin/re: line 18: [: Alchemist: binary operator expected
/home/ashwin/bin/re: line 14: [: too many arguments
Lines 14 and 18 are if [ array_contains2 $team1 "Alchemist" "Axe" ]
and if [ array_contains2 $team2 "Alchemist" "Axe" ]
respectively.
Is the error because of IFS. If not what is the cause for the error?