I am writing a script that compares the first 3 letters of every line (by using cut to get them) in a file to strings inside an Array. I have already looked around but the solutions i found didn't work on my system.
Right now It looks like this:
weekdays=([Mon]=1 [Tue]=1 [Wed]=1 [Thu]=1 [Fri]=1 [Sat]=1 [Sun]=1) input="/Foo/Bar.log" while read -r line do cutline="$(echo ${line} | cut -c 1-3" if [[ ${weekdays["$cutline"]} ]] then echo "Match" else echo "No Match" fi done < ${input}
The Line gets cut properly but something during the test returns a false Positive since no matter what the first 3 Letters are it returns a "Match".
When I checked the script with -x it showed me, instead of the actual test that it instead used
[[ -n 1 ]]
And when I tested it with the [ ]
expresion it showed a 1
Does it check for every single char in the array and not just the whole words, or is there something else wrong with it?
If there is no problem, is there another way to compare the first 3 letters of a line to everything insde an array before continuing with the next?
As a side note: I am indeed running Bash 4, so associative arrays should work