[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ls: avoiding error msg on non-existant file

From: Karl O. Pinc
Subject: Re: ls: avoiding error msg on non-existant file
Date: Fri, 22 Nov 2002 04:03:49 -0600

On 2002.11.22 00:36 Bob Proulx wrote:
Karl O . Pinc <address@hidden> [2002-11-18 14:33:30 -0600]:
> To keep there error from coming up, I can
> 2>/dev/null
> if [ ! -e . ] ; then ls pattern ; fi
> but niether of these solutions is particularly elegant.
> The first throws all errors away, and I want to know if
> there are any other errors.  The second assumes that
> there will only be files in the directory when the directory
> also contains files matching <pattern>.

The first is rather like this.

  for file in pattern ; do
    if [ ! -f "$file" ]; then
      echo "$file: no such file" 1>&2

You did not really say what you were trying to do.  Therefore it is
hard to suggest alternatives.


What I am trying to do is take advantage of the pattern expansion
capabilities of the shell.
I want to pipe the result of the shell's pattern expansion to
the remainder of my program, but I don't want to feed the
right side of the pipe a file that doesn't exist, the pattern
expands to iteslf when there's no matching directory entry.
I attempted to use ls as a filter to remove non-existant
pathnames, a task beyond ls.

You are right, I can filter shell pattern expasion with:

  for f in pattern ; do
    if [ -e "$f" ] ; then
      echo "$f"

I'm just searching for an existance filter command, so I don't
have to code the loop.  'ls -d', which lists files which _do_ exist
just rolled off my fingers. I've no compelling reason not to code the loop, just lazyness.

Thanks for the help.

Karl <address@hidden>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]