![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to check for empty file in Perl? | deepakwins | UNIX for Dummies Questions & Answers | 1 | 03-04-2008 11:00 AM |
| Check for empty string | rahman_riyaz | Shell Programming and Scripting | 12 | 01-23-2008 11:13 PM |
| Check for Empty Command Argument | Nysif Steve | UNIX for Dummies Questions & Answers | 6 | 09-19-2007 12:59 PM |
| How to check for null or empty string | doer | Shell Programming and Scripting | 5 | 07-23-2007 10:31 PM |
| 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 12:14 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
check if file is empty
How do I check if a file is empty in a sh script
I want to test in my shell script if the output file is empty and if it is do one thing and if it isnt empty do another? any ideas? |
| Forum Sponsor | ||
|
|
|
||||
|
Quote:
Code:
$ ls $ touch file_1 $ dd if=/dev/zero of=$HOME/tmp/file_2 bs=1 count=100 100+0 records in 100+0 records out $ ls -l file_1 file_2 file_3 ls: file_3: No such file or directory -rw-rw-r-- 1 foo bar 0 Sep 24 20:28 file_1 -rw-rw-r-- 1 foo bar 100 Sep 24 20:28 file_2 $ [[ -s file_1 ]] $ echo $? 1 $ [[ -s file_2 ]] $ echo $? 0 $ [[ -s file_3 ]] $ echo $? 1 ZB |
|
||||
|
Quote:
|
|
|||
|
this is just another way of doing it
a round about one Code:
if [ `ls -l <file> | awk '{print $5}'` -eq 0 ]
then
//condition for being empty
else
//condition for not being empty
fi
|
|
|||
|
I have a requirement where if file size is 487 then ignore it otherwise put into e-mail script? I can do it using -s but it does only if file is empty...
any clue on this please??? |
|||
| Google UNIX.COM |