mercredi 16 août 2017

Linux unexpected operator/operand while testing for files

I have the following simple ksh script used in Linux

#!/bin/ksh
set -x
### Process list of *.dat files
if [ -f *.dat ]
then
print "about to process"
else
print "no file to process"
fi

I have the following *.dat files in my current directory:

S3ASBN.1708140015551.dat S3ASBN.1708140015552.dat S3ASBN.1708140015561.dat S3HDR.dat 

Running file command shows the following:

file *.dat
S3ASBN.1708140015551.dat: ASCII text
S3ASBN.1708140015552.dat: ASCII text
S3ASBN.1708140015561.dat: ASCII text
S3HDR.dat:                ASCII text

However, when I run the ksh script, it shows the following:

 ./test
+ [ -f S3ASBN.1708140015551.dat S3ASBN.1708140015552.dat S3ASBN.1708140015561.dat S3HDR.dat ]
./test[9]: [: S3ASBN.1708140015552.dat: unexpected operator/operand
+ print  no file to process
 no file to process

Any clue why I am getting unexpected operator/operand and what's the remedy?

Aucun commentaire:

Enregistrer un commentaire