executing/including command in mailx subject line

Hi,
Is it possible for me to include the results from a command in the subject line? What I am looking to do is get the file count and include it into the subject line as well as the list of files in the body.

Example Subject line: Currently 25 files in directory

My Code:

#!/bin/ksh
cd /opt/app/mydirectory
ls -otrg|awk '{print $4 " " $5 " "$6 " "$7}' | /usr/bin/mailx -s "Currently #want to run ls -l | wc -l here# files in directory" email@email

I am a little new to scripting so I appreciate the help.

I can successfully email me the list of files out, formatted how I need, but would like to include the file count in the subject of the email.

Running on solaris 10.

Thanks,
Ozifer

I have not tried to execute a command within the subject line but often include variables. You can try executing the command using "`" back ticks like;

ls -otrg|awk '{print $4 " " $5 " "$6 " "$7}' | /usr/bin/mailx -s "`ls -l | wc -l` files in directory" email@email

or if that does not work

num_files="`ls -l | wc -l`"
ls -otrg|awk '{print $4 " " $5 " "$6 " "$7}' | /usr/bin/mailx -s "Currently $num_files files in directory" email@email

[/code]

or add an attachment

ls -l /path/to/directory | uuencode listing | mailx -s "file count: $(ls |wc -l)" me@mycompany.com