Need help embedding Unix commands in a shell script

Hi Folks,

I have a text file which may or may not have any data.
I would like to email the file, via a Korn shell script, if the file is not empty.

I am fiddling around with the wc -l command, but no luck so far. The pseudo code is as follows

count=`wc -l test.txt`

if [$count > 0]
cat test.txt | mailx -s "Test File" email.yahoo.com
endif;

As of right now, the "count" variable has more information than required and the information is being saved as string and not as integer.

Can somebody please show me the exact syntax? or provide an alternate way of doing this?

Thanks in advance

rogers42

use

wc -l < test.txt
 mailx -s "Test File" email.yahoo.com < test.txt 
```[/i][/b]

If you're just trying to tell if the file is empty, you can do this:

[ -s "test.txt" ] && mailx -s "test file" email.yahoo.com < test.txt

-s means "file exists, and is not empty".

1 Like
if [ -s test.txt ]; then echo "File exists and has size > 0"; fi

tyler_durden

1 Like

Hi Folks,

Thanks to everybody who took the time to reply. And especially to the last two posters for sharing such elegant yet simple code.

Exactly, what I was looking for.

Thanks

rogers42