Sponsored Content
Full Discussion: Linux test command
Operating Systems Linux Linux test command Post 53443 by Ygor on Thursday 15th of July 2004 06:23:35 AM
Old 07-15-2004
Another way to test for files
Code:
if ls /home/pv/T20* >/dev/null 2>&1
then
    echo true
fi

However, this would return true for directories and empty files. Since you want to do some processing on the files why not use a for loop...
Code:
for file in $(ls /home/pv/T20*)
do
   [ -s $file ] || continue
   echo do something with $file
   :
done

If there are no files then the code within the for loop is not executed and this message is sent to standard error: "/home/pv/T20* not found"

PS: It is not good practice to rely on "if test -f" for multiple files. Here's why (on HP-UX)....

$ ls *.txt
b.txt c.txt
$ if test -f *.txt
> then
> echo true
> else
> echo false
> fi
true
$ mkdir a.txt
$ if test -f *.txt
> then
> echo true
> else
> echo false
> fi
false
 

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

2. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

3. IP Networking

A wireless test tool for linux?

hi all: I want to find a wireless test tool for linux , just linke netstumbler on windows . i find the tool for long time , but i cann't find one. does somebody give a advice. thanks!!! (0 Replies)
Discussion started by: arnold.king
0 Replies

4. Shell Programming and Scripting

Capture the data in Linux .While doing load test.

Hi All, I am trying to capture the data in linux .While doing load test. is there's any sample script please help me. Linux test4 2.6.18-308.8.1.el5 #1 SMP Fri May 4 16:43:02 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux Thanks, (5 Replies)
Discussion started by: sam1226
5 Replies
ZIPARCHIVE.OPEN(3)							 1							ZIPARCHIVE.OPEN(3)

ZipArchive::open - Open a ZIP file archive

SYNOPSIS
mixed ZipArchive::open (string $filename, [int $flags]) DESCRIPTION
Opens a new zip archive for reading, writing or modifying. PARAMETERS
o $filename - The file name of the ZIP archive to open. o $flags - The mode to use to open the archive. o ZipArchive::OVERWRITE o ZipArchive::CREATE o ZipArchive::EXCL o ZipArchive::CHECKCONS RETURN VALUES
o $Error codes - Returns TRUE on success or the error code. o ZipArchive::ER_EXISTS File already exists. o ZipArchive::ER_INCONS Zip archive inconsistent. o ZipArchive::ER_INVAL Invalid argument. o ZipArchive::ER_MEMORY Malloc failure. o ZipArchive::ER_NOENT No such file. o ZipArchive::ER_NOZIP Not a zip archive. o ZipArchive::ER_OPEN Can't open file. o ZipArchive::ER_READ Read error. o ZipArchive::ER_SEEK Seek error. EXAMPLES
Example #1 Open and extract <?php $zip = new ZipArchive; $res = $zip->open('test.zip'); if ($res === TRUE) { echo 'ok'; $zip->extractTo('test'); $zip->close(); } else { echo 'failed, code:' . $res; } ?> Example #2 Create an archive <?php $zip = new ZipArchive; $res = $zip->open('test.zip', ZipArchive::CREATE); if ($res === TRUE) { $zip->addFromString('test.txt', 'file content goes here'); $zip->addFile('data.txt', 'entryname.txt'); $zip->close(); echo 'ok'; } else { echo 'failed'; } ?> PHP Documentation Group ZIPARCHIVE.OPEN(3)
All times are GMT -4. The time now is 03:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy