How can I make my script check to see if a file is empty?
I need to make my script check to see if a text file is empty so I can fork the process depending on whether or not it is. How do I do that?
|
Something like this...
Code:
#!/bin/bash |
Quote:
fsize = $(stat -c %s $1) The result of both is the same. Not an advise only how i make it cos the backtick could be overseen in an hot programming session. Happy new year. |
Thanks for the tip LiNuXkOlOnIe ! :)
|
Bash has a built-in test for this and many other file attributes (see the bash manpage). The "-s" option tests for a file with non-zero size.
Code:
#!/bin/bash |
Jaaauu. And the oscar goes tooo ...
jcliburn. thank you. Don't worry only spamming. :-))) |
One caveat with the -s method... It returns false under TWO conditions: the file size is zero, OR if the file doesn't exist. So if you feed my sample script a nonexistent file name, it'll say "File size is zero".
|
All times are GMT -5. The time now is 03:52 PM. |