Trying to compare two arrays and print the differences, and getting below error.
1.sh: line 9: syntax error near unexpected token `<'
1.sh: line 9: ` mapfile -t $1 < <(comm -23 <(echo "${a[*]}" | sort) <(echo "${b[*]}" | sort))'
If I run in command prompt its working fine and giving the results correctly. Whine i copy same code in 1.sh its throwing error
below is the code
a=(1 2 3 4 5 6 7 9 10 11 12)
b=(2 3 4 7 8 9 12)
function array_diff
{
eval local a=\(\"\${$2[@]}\"\)
eval local b=\(\"\${$3[@]}\"\)
local IFS=$'\n'
mapfile -t $1 < <(comm -23 <(echo "${a[*]}" | sort) <(echo "${b[*]}" | sort))
}
array_diff RESULT a b
echo "${RESULT[@]}"
Output should be: 1 10 11 5 6