Vinu, Uma wrote:
> Hi,
> 
>  
> 
> ls -l <Dir> | grep core | wc -l  ----- The directory doesn't has the
> core file.
> 
> But wc -l returns a blank line instead of a 0. I need the output to be
> 0. 
> 
> Why does this happen? Your reply will be of great help.

My version of wc (5.2.1) does return 0.
You should say exactly what software you have when reporting problems.

I notice this `grep something | wc -l` idiom a lot.
Usually one is checking a boolean condition so
the following is better:

if ls /dir | grep core >/dev/null; then
    echo "Core file found"
fi

Or if your grep supports it:

if ls /dir | grep -q core; then
    echo "Core file found"
fi

This still has the problem where legimitate files
like "scores.txt" for example will be flagged.
So you probably want to do:

if ls /dir | grep -q '^core$'; then
    echo "Core file found"
fi

Pádraig.


_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to