Some problem about file test

Hi,
I'm writing a part of script to test the files, here is what is looks like:
if [ -r /test/A*.TXT ]
then
do somthing
fi

This script runs well on HPUX. However, when I test it on Linux(redhat), it only works if there is only one file with name A*.TXT. If there's more than one files with this kind of name in that directory, the test will never pass.
Can anyone help me with this? Thanks a lot!

You cant check the readability of all files at one time, you need to do it one by one.

Please put code inside code tags.

With which shell? It wouldn't work in any Bourne-type shell.

for file in /test/A*.TXT
do
  if [ -r "$file" ]
  then
    : do something
  fi
done

This one works too, tested on gentoo, bash 3.1.16

for i in $( find /test -iname "A*.TXT" );
do
	if [ -r "${i}" ] ; then
		printf "Test OK\n"
	else
		printf "Test NG\n"
	fi
done

I'll bet you didn't test it in a directory where there's a matching filename containing a space.

oops!! ur correct cfajohnson,
never thought of spaces in a file name,
sorry abt that.

Thanks, your code is ok!

BTW, my original code really works on my HPUX :frowning:
The first line is #!/bin/sh, how can I check the exact version?

Are you sure it works when there are multiple matching files? I've never heard of a Bourne-type shell where that would work.

Yes, this part is taken from a script which has been running on our HPUX system for years. Now we are migrating the system to Linux, that's how we found this problem.