I have an array of domains that I am attempting to iterate through and check if a string from a file matches any of the domains in the array. However, when the for loop starts, I get an error
line 64: www.google.com: syntax error: invalid arithmetic operator (error token is ".google.com")
the array and for loop look like this:
sites=("www.google.com" "www.bing.com" "www.yahoo.com" "www.duckduckgo.com") while read line; do csvString=$(echo "$line"); greppedDomain=$(echo "$line" | grep -Eo '[A-Za-z0-9]{2,62}\.[A-Za-z0-9]{2,62}\.[A-Za-z]{2,62}'); for i in "${sites[@]}"; do if [ "$greppedDomain" = "${sites[$i]}" ] then sitesOut+=($csvString); fi done done < sitelist.txt
I am currently at a loss, maybe it is an issue with the way the grep output stores in the variable?
csvString=($echo "$line")
is wrong. You have no variable calledecho
. You just wantcsvString=$line
since you're not using thecsvString
variable as an array. But you might as well useread csvString
directly.