It is currently Thu, 20 Jan 2022 10:12:51 GMT



 
Author Message
 how to check existence of multiple files in if-clause ?
Hello all,

I want to test the existence of any file with the extension ".edi" in a directory, but if I check for any file
(*.edi) like the following lines, it doesn't work. Does anybody know which parameter I have to use?
Or can give me somebody a hint?
-----------
if [ -e /home/test/*.edi ]
then
  .....
else
  ....
fi
----------
Thanks!
Regards,
Jens



 Fri, 08 Sep 2006 23:57:19 GMT   
 how to check existence of multiple files in if-clause ?

find /home/test -type f -iname "*edi"
man find

B.
--
He who laughs last is slow on the uptake.



 Sat, 09 Sep 2006 00:08:22 GMT   
 how to check existence of multiple files in if-clause ?

Hint: use the 'ls' command.

ls *.edi 1>/dev/null 2>&1 && echo '*.edi files exist' || echo 'no *.edi files'



 Sat, 09 Sep 2006 03:06:33 GMT   
 how to check existence of multiple files in if-clause ?

if ( set -- *.edi; [ "$1" = "*.edi" ] )
then
   echo "No such file"
else
   echo "$@"
fi

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License



 Sat, 09 Sep 2006 06:20:40 GMT   
 how to check existence of multiple files in if-clause ?
On 22 Mar 2004 22:20:40 GMT, Chris F.A. Johnson <c.fa.john...@rogers.com> wrote:

The parentheses evaluate the enclosed expression within in a
sub-shell, thus the "$@" does not get set. Use a group command
instead:

if { set -- *.edi; [ "$1" = "*.edi" ]; }
then
   echo "No such file";
else
   echo "$@"
fi

Cheers,
--
Why is there only one Monopolies Commision?



 Sat, 09 Sep 2006 09:11:55 GMT   
 how to check existence of multiple files in if-clause ?

    The point of using parantheses is that it IS executed in a
    subshell, and doesn't affect existing positional parameters.

    Instead of 'echo "$@"', 'echo *.edi' would list the files.

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License



 Sat, 09 Sep 2006 15:24:29 GMT   
 how to check existence of multiple files in if-clause ?
In article <slrnc5v3mr.htl.n...@news.ops.mine.nu>,
Neil Woods  <n...@suespammers.org> wrote:

I do not see the reason "set -- *.edi" to be in the if clause. I would say:

set -- *.edi
if [ "$1" = "*.edi" ]
then
   echo "No such file";
else
   echo "$@"
fi

or it is better to say:

set -- *.edi
if [ -e "$1" ]
then
   echo "No such file";
else
   echo "$@"
fi
--
Michael Wang * http://www.unixlabplus.com/ * mw...@unixlabplus.com



 Thu, 28 Dec 2006 14:54:55 GMT   
 how to check existence of multiple files in if-clause ?

if find *.edi > /dev/null; ...
if ls *.edi > /dev/null; ...

--
William Park, Open Geometry Consulting, <opengeome...@yahoo.ca>
Toronto, Ontario, Canada



 Thu, 28 Dec 2006 18:14:48 GMT   
 
   [ 8 post ] 

Similar Threads

1. need help on checking existence of file using autoconf

2. newbie: check the existence of a file

3. (t)csh file existence check with wildcards

4. Checking for file existence and killing a process

5. check file's existence in tclsh

6. Checking file existence ...

7. sh: How check for wildcarded files existence (e.g., *.gif)

8. ksh: Checking for file existence

9. Tool, which checks the existence of different MAC-Address in a network

10. How to check for process existence


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software