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
tpm_selftest(8) 					      System Manager's Manual						   tpm_selftest(8)

							  TPM Management - tpm_selftest

NAME
tpm_selftest - request TPM perform selftest and report SYNOPSIS
tpm_selftest [OPTION] DESCRIPTION
tpm_selftest requests that the system's TPM perform a self test (via the TPM_SelfTestFull API) and report the results. The --results option reports the outcome of the last self test operation without requesting that another test be executed. If the TPM fails the self test, it enters failure mode where no commands are accepted. The results are reported in a manufacturer specific format. The TPM's self test is always executed automatically at every boot. -h, --help Display command usage info. -v, --version Display command version info. -l, --log [none|error|info|debug] Set logging level. -r, --results Report results only. SEE ALSO
tpm_version(1), tpm_takeownership(8), tpm_setownable(8), tcsd(8) REPORTING BUGS
Report bugs to <trousers-users@lists.sourceforge.net> TPM Management 2005-04-25 tpm_selftest(8)
All times are GMT -4. The time now is 11:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy