binary operator expected error

It is erroring for : binary operator expected on the
if [ -r EPISGCHGS*.txt ] line.
Any suggestions?

Thanks in advence.

Add a trace option to verify the test that is executed :

set -x
if [ -r EPISGCHGS*.txt ]
. . . .
set +x

Jean-Pierre.

Globbing means expanding wildcards into the file the wildcard (metacharacter) represents.

If you have three files that match EPISGCHGS*.txt your statement becomes


if [ -r EPISGCHGSa.txt EPISGCHGSb.txt  EPISGCHGSc.txt ] 

which means the syntax is wrong: -f takes one file name

Actually I have some text files in the directory that starts with EPISGCHGS.
Here I am checking if there is no file with the above extension then exit else copy all the files that start with EPISGCHGS to one file called ultisource.txt .
##############################
if [ -r EPISGCHGS*.txt ]
then
for file in EPISGCHGS*.txt
do
cat $file > ultisource.txt
done
else
echo no files found....exiting
exit 0
fi
##############################

Thanks in advance.

To add something here..
It is handling for a single file well, but if it has more files then it is erroing with the above error.

Thanks

Try to change the logic of your script:

filespec='EPISGCHGS*.txt'
for file in $filespec
do
   if [ "$file" = "$filespec" ]
   then
      echo no files found....exiting
      exit 0
   fi
   cat $file >> ultisource.txt
done

Jean-Pierre.

set -- EPISGCHGS*.txt
[ -r "$1" ] && cat EPISGCHGS*.txt > ultisource.txt

Thanks.
It worked.