Expect : what is the equivalent to ksh if -s

In Ksh to check if file exists and is non zero ..


if [ ! -s $FILE ];
then
        echo "Error $FILE does not exists!"
else
        echo "$FILE found!"
fi

Cant seem to find the Expect equivalent ....

Any help is greatly appreciated.

In Expect you can use "file exists" and/or "file size" to get the status of a file:

#!/usr/bin/expect -f

set filename "/tmp/file"
set file_status [file exists $filename]
if { $file_status > 0 } {
    set retcode [file size $filename]
    puts "$filename exists and is $retcode bytes."
} else {
    puts "$filename not found!"
}
1 Like

Thank you.

But I was playing around with this .. curious why its not working .. but I actually like your code. It reads better.

set fnam "/home/popeye/testfile"
send_user "$fnam\n"
expect {
          "$fnam" {
                     send_user "found\n"
                     }
           timeout {
                      send_user "not found\n"
                      }
}