I was trying to test the presence of some files on Red hat Linux enterprise version 2.4.9 using the following command
test -f /home/pv/T20*
I am getting the error, too many parameters, when I have multiple files starting with T20 on that directory. When there is no files or just one file, no errors and the command works.
Any idea whay I can't check the presence of multiple files? Or is there any other command I can use for this purpose.
I just want to see(by a a single commad) if there is any file starting with those letters present in that directory so that I can do some processing on those files. test -f /home/pv/T20* command works perfect on HP-UX and I assume it is a bug on this flavor of Linux.
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
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)
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)
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)