I am trying to do a simple comparison to check if a line is empty using bash:
line=$(cat test.txt | grep mum )
if [ "$line" -eq "" ]
then
echo "mum is not there"
fi
But it is not working, it says: [: too many arguments
Thanks a lot for your help!
You could also use the
$?variable that is set to the return status of the command. So you’d have:For the
grepcommand if there are any matches$?is set to 0 (exited cleanly) and if there are no matches$?is 1.