I am trying to check if items in an array options
are in a file $file
using the following simplified code:
options=(
A
B
C
)
for i in "${options[@]}"; do
if grep -F $file "${i}" = false; then
echo "${i}"
fi
done
I expect this to output A, B, or C if they are not present in $file
, but instead it outputs for A, B, and C:
grep: A: No such file or directory
grep: =: No such file or directory
grep: false: No such file or directory
From this, it seems that grep is interpreting all arguments as files to either check or check with, which also implies that the boolean in the if statement does not have the correct syntax. So my question is twofold:
- How can I use grep or another command to check if an element in the array is in
$file
? - How can I prevent this command from interpreting the boolean as an argument instead of leaving it as part of the if statement?