Here is a simple code snippet which checks for the existence of a file and that it is NOT empty to return TRUE and it returns FALSE otherwise.
if [ -s test_file ] ### if the test_file exists and that it is not empty
### i.e., file has contents
then
echo "TRUE" ### returns 'true' ONLY if the file exists and it is NOT empty,
### i.e., file has contents - file is not of 0 bytes in size
else
echo "FALSE" ### returns 'false' if the file exists and it is empty
### (0 bytes in size).
### returns 'false' also if the file does not exist
fi
For different results to appear, try creating a file 'test_file' and by changing its contents to make it a sized file and/or to make it an empty file.
No comments:
Post a Comment