![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| check if file is empty | stolz | Shell Programming and Scripting | 8 | 03-22-2009 11:15 PM |
| How to check if a file is empty? | shreekrishnagd | UNIX for Dummies Questions & Answers | 1 | 09-09-2008 08:21 AM |
| How to check for empty file in Perl? | deepakwins | UNIX for Dummies Questions & Answers | 1 | 03-04-2008 03:00 PM |
| Check for empty string | rahman_riyaz | Shell Programming and Scripting | 12 | 01-24-2008 03:13 AM |
| How can I make the for command check to see if a file is empty before executing? | chrchcol | Shell Programming and Scripting | 3 | 07-29-2006 03:14 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
to check if file is empty or not and return a non zero value
Hi All,
I am new to unix worldd . I need to check a file1 if its empty or not. If its empty then return a non zero value say 99 could you pls let me know the perl script for this. |
|
||||
|
The shell does it - normal return values are: zero == true anything else == false
Code:
#one way
if [[ -s filename ]] ; then
echo "filename exists and is > 0 bytes"
else
echo "filename does not exist or is zero length"
fi
# another way
if [[ -f filename ]] ; then
if [[ -s filename ]] ; then
echo "filename exists and is > zero"
else
echo "filename exists and == zero "
fi
else
echo "filename does not exist"
fi
|
![]() |
| Bookmarks |
| Tags |
| shell script, shell scripting, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|