4

I have a simple shell script that executes a .sql script. When the .sql script has completed, the shell script sends an email to a specified address notifying whether or not the .sql script ran successfully.

My problem is that the subject line is being truncated. I am using a simple IF statement to determine the 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

This works fine. However, when I execute the mailx command, the subject line is truncated to "Development" or "Production" depending on the version of the script that has been executed:

mailx -s $SUBJECT $EMAIL < $MAILFILE

I know the subject line needs to be in double quotes if it includes embedded spaces, but this does not seem to work correctly when assigned to a variable.

Is there a way around this? Is there a way to escape the double quotes

1 Answer 1

7

You need to quote $SUBJECT as you use it, i.e.

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

Also there should be no space in

SUBJECT="$VERSION script successful"
Sign up to request clarification or add additional context in comments.

2 Comments

It seems to work (mostly) when I do this: "${SUBJECT}". However, since the $SUBJECT is being assigned a string as a variable ($VERSION), the string is now "$VERSION script successful" or "$VERSION script had error(s)". Any idea how to get the variable $VERSION to resolve as a string?
1. I note that you have a space in one of your assignments, like SUBJECT= "....". 2. The behaviour you describe sounds like you reall have single quotes on your assignment, i.e. SUBJECT='...'`. Going to bed now. Will check in the morning. Good luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.