From owner-freebsd-questions Sat May 31 14:13:09 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id OAA13220 for questions-outgoing; Sat, 31 May 1997 14:13:09 -0700 (PDT) Received: from castor2.freiepresse.de (castor2.freiepresse.de [194.25.232.30]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id OAA13208 for ; Sat, 31 May 1997 14:13:05 -0700 (PDT) Received: from dialup.freiepresse.de (ppp-pln182.freiepresse.de [194.25.234.182]) by castor2.freiepresse.de (8.8.4/8.8.4) with SMTP id WAA13852; Sat, 31 May 1997 22:12:00 -0100 (Etc/GMT) Message-ID: <33909140.40FE@abo.freiepresse.de> Date: Sat, 31 May 1997 22:59:44 +0200 From: Gerhard Sittig X-Mailer: Mozilla 3.01 [de] (Win95; I) MIME-Version: 1.0 To: Gianmarco Giovannelli CC: FreeBSD-questions Subject: Re: test and multiple files ... References: <3.0.1.32.19970529201527.00697bd8@giovannelli.it> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-questions@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk Gianmarco Giovannelli wrote: > > How it is possible use the test command with multiple files ? > > i.e. > > if [ -f /usr/tmp/src-2.2* ]; then > mv /usr/tmp/src-2.2.????.gz > /home/ftp/pub/FreeBSD/FreeBSD-2.2/ctm > fi > > seems not to work for me.... > In all the cases where wildcards are used, it's a good idea (seems to me at least :) to use an `echo` command and see what command the shell will generate after expanding these patterns. In the above example the code will read somewhat like if [ -f file1 file2 file3 ]; then ... which does work when only ONE file is matched and MIGHT work this way without being noticed of that error. But referring to the 'test' synopsis this is of course a mistake. One solution for the above problem would be for file in /usr/tmp/src-2.2*; do if [ -f $file ]; then mv $file $destdir; fi done which will even cope with non matchinng files (i.e. empty lists). This might look somewhat more of a circumstance compared to Doze, but it would be even worse when wildcards wouldn't work :)