Executing the mailx command in a shell script

I have a simple script shell that runs a .sql script. When the .sql script is complete, the shell script sends an email to the specified address, notifying if the .sql script has been successfully executed.

My problem is that the subject line is truncated. I use a simple IF statement to define a subject line:

grep 'ORA-' $OUTFILE > /dev/null 2>&1
if [ $? = 1 ]; then
    ERRORS=n
    SUBJECT= "$VERSION script successful"
else
    ERRORS=y
    SUBJECT="$VERSION script had error(s)"
fi

It works great. However, when I execute the mailx command, the subject line is truncated to "Development" or "Production" depending on the version of the script that was executed:

mailx -s $SUBJECT $EMAIL < $MAILFILE

I know that the subject line should be in double quotes if it includes nested spaces, but this does not work correctly when assigning a variable.

Is there any way around this? Is there a way to avoid double quotes

+3
1

$SUBJECT, , ..

mailx -s "$SUBJECT" $EMAIL < $MAILFILE

SUBJECT="$VERSION script successful"
+6

All Articles