I've got a script with this snippet:
if [ -s $DATA_DIR/file.dat ]
then
I know that the -s indicates that the file exists and is not empty. How can I specify that the file exists, but is empty? I thought I could do:
if [[ -a $DATA_DIR/file.dat && ! -s $DATA_DIR/file.dat ]]
then
But this generates a "else unmatched" error on the else that follows.
if [ ! -s $DATA_DIR/file.dat ]
then
But wouldn't that test to true if either:
File does not exist OR
File exists but is empty
If so, I don't think that would work for me because I want something different to happen for each of those two scenarios.
If file does not exist, do this
If files exists, but is empty, do this
if [ ! -f file1 ]
then
echo "no such file"
fi
if [ ! -s file1 ]
then
echo "file exists but empty"
fi
Aha...when I looked at man ksh for -f, it said:
-f file
TRUE, if file exists and is an ordinary file.
What does "ordinary file" mean?
Ordinary = A regular disk file - data, text, executable, etc.