I'm reading a file like
state 100 NULL
operator 2 0 3 NULL
and I want to parse it to an array line wise to check it for certain conditions so what i actual do is:
#!/bin/bash
fileLines=$(cat file)
IFS=$'\n'
for line in $fileLines
do
IFS=$' ' read -r -a lineArray <<< $line
echo ${lineArray[@]}
if [[ ${lineArray["state"]} ]] ;
then
echo "hit"
fi
done
but it unfortunately comes back with the output
state 100 NULL
hit
operator 2 0 3 NULL
hit
even if I check for equality by using
if [[ ${lineArray[0]} == "state" ]] ;
it is still ignoring the condition I gave to the script. Is there a better way to check my array for conditions?
if [[ ${lineArray[0]} == "state" ]] ;works for me