[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Query on wc
From: |
Pádraig Brady |
Subject: |
Re: Query on wc |
Date: |
Wed, 09 Aug 2006 14:49:19 +0100 |
User-agent: |
Mozilla Thunderbird 1.0.8 (X11/20060502) |
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.