I'm trying to write a simple script that if a line has 7 commas in it, either true or false will be returned. But I'm running into a couple of errors. The first error is coming from the grep, if I remove the -o, I still receive the error. And I'm not sure why 0 is being displayed and why it's returning as false? I'm also having trouble with equal; as in neither -eq or == is working.
Script:
#!/bin/bash
str="a,g,5,d,s,c,f,s"
stat=grep -o "," <<< "$str" | wc -l
if [ $stat == '7' ];then
echo "true"
else
echo "false"
fi
Here is the output I'm receiving:
./tesh.sh
./tesh.sh: line 3: -0: command not found
0
./tesh.sh: line 4: [: ==: unary operator expected
false