Using the test built-in to compare my variable to an array fails with error "Syntax error in expression"
.
I've tried requoting the var_names, using == and -eq, and several old tricks from SO questions from 8+ years ago.
#!/bin/bash
TOTAL=0
declare -a FREQ=(0);
main(){
for i in $(cat "$1");
do
TOTAL=$(( $i + FREQ[-1] ))
echo Total is $TOTAL
if [[ $TOTAL -eq "${FREQ[@]}" ]];
then
echo "Matching Frequency Found: " $TOTAL
exit
else
FREQ=(${FREQ[@]} $TOTAL)
fi
done
return $TOTAL
return $FREQ
}
main $@
I expect $TOTAL to be found in the array of $FREQ when the script is called with ./script.sh input.txt
which holds over 1000 integers.